462 Commits

Author SHA1 Message Date
Michael Goderbauer
3f09b23338
cleanup now-irrelevant ignores for deprecated_member_use (#143403)
Follow-up to https://github.com/flutter/flutter/pull/143347.
2024-02-14 21:08:25 +00:00
Aizat Azhar
75a2e5b493
Reset framesEnabled to default value at the end of each test (#141844)
Reset `framesEnabled` to `true` at the end of each test as otherwise subsequent tests may fail when pumping a widget

Fixes #141835
2024-01-30 16:04:15 +00:00
Greg Spencer
0dea82e684
Remove unneeded expectation in test (#141822)
## Description

This removes an unneeded expectation in the test for the AppLifecycleListener.  It's unneeded because the test immediately resets the state anyhow.  I'm removing it because the web implementation sets the value when initializing, so it's never initially null there.

## Related PR
 - https://github.com/flutter/engine/pull/44720#issuecomment-1898482363
2024-01-22 19:46:10 +00:00
Satsrag
c033b08df7
fix: cannot input new line using custom input control (#140356)
For https://github.com/flutter/flutter/issues/125875 and https://github.com/flutter/engine/pull/45522

According to [this discussion](https://github.com/flutter/flutter/pull/139446#discussion_r1424776370), Just added `forceMultiline` to JSON on `_configurationToJson`. @LongCatIsLooong @Renzo-Olivares
2024-01-03 01:58:24 +00:00
Polina Cherkasova
baf739c8e6
Remove usage of testWidgetsWithLeakTracking. (#140239) 2023-12-15 14:13:31 -08:00
Greg Spencer
a33dec1a27
Deprecate RawKeyEvent, RawKeyboard, et al. (#136677)
## Description

This starts the deprecation of the `RawKeyEvent`/`RawKeyboard` event system that has been replaced by the `KeyEvent`/`HardwareKeyboard` event system.

Migration guide is available here: https://docs.flutter.dev/release/breaking-changes/key-event-migration

## Related Issues
 - https://github.com/flutter/flutter/issues/136419

## Related PRs
 - https://github.com/flutter/website/pull/9889
2023-12-11 22:19:18 +00:00
Kostia Sokolovskyi
f05bb9a182
Instrument RestorationBucket, _RouteEntry and DisposableBuildContext for leak tracking. (#137477) 2023-10-28 13:27:00 -07:00
Greg Spencer
5907c9757e
Add isLogicalKeyPressed to KeyEvent (#136856)
## Description

Adds some convenience methods to `KeyEvent` that allow testing to see if a logical or physical key is pressed from the event object. These are similar to the ones already on `RawKeyEvent`, and will make migration the to `KeyEvent` easier (so it could more easily be a `flutter fix` migration).

Added:

- `bool isLogicalKeyPressed(LogicalKeyboardKey key)`
- `bool isPhysicalKeyPressed(PhysicalKeyboardKey key)`
- `bool get isControlPressed`
- `bool get isShiftPressed`
- `bool get isAltPressed`
- `bool get isMetaPressed`

## Related Issues
 - https://github.com/flutter/flutter/issues/136419

## Tests
 - Added tests for the new methods.
2023-10-27 18:52:08 +00:00
Bruno Leroux
b2ec34fcb4
Add ProcessTextService (#137145)
## Description

This PR adds `ProcessTextService` on the framework side to communicate with the engine to query and run text processing actions (on the engine side, only Android is supported currently, see https://github.com/flutter/engine/pull/44579).

## Related Issue

Non-UI framework side for https://github.com/flutter/flutter/issues/107603

## Tests

Adds 3 tests.
2023-10-26 11:44:07 +00:00
林洵锋
047bd6cebd
Fix the character field of RawKeyEvent is always null on iOS (#135100)
Fixes https://github.com/flutter/flutter/issues/133956
2023-10-03 05:26:41 +00:00
Kostia Sokolovskyi
4204f07d76
Add RestorationManager disposals in test/services/restoration_test.dart. (#135218) 2023-09-21 10:24:52 -07:00
Polina Cherkasova
77718845dd
Handle breaking changes in leak_tracker. (#135185) 2023-09-21 10:06:21 -07:00
derdilla
a0406cccb1
Mark ReastaurationManager not disposed (#134832) 2023-09-20 16:46:14 -07:00
derdilla
2868bc1351
Fix leak in hardware_keyboard_test.dart (#134380) 2023-09-20 16:45:15 -07:00
derdilla
9b767e6c1f
cover more tests with leak tracing (#134833) 2023-09-20 12:21:10 -07:00
David Iglesias
c7c9d8eea6
[web] Encode AssetManifest.bin as JSON and use that on the web. (#131382)
This PR modifies the web build slightly to create an `AssetManifest.json`, that is a JSON(base64)-encoded version of the `AssetManifest.bin` file.

_(This should enable all browsers to download the file without any interference, and all servers to serve it with the correct headers.)_

It also modifies Flutter's `AssetManifest` class so it loads and uses said file `if (kIsWeb)`.

### Issues

* Fixes https://github.com/flutter/flutter/issues/124883

### Tests

* Unit tests added.
* Some tests that run on the Web needed to be informed of the new filename, but their behavior didn't have to change (binary contents are the same across all platforms).
* I've deployed a test app, so users affected by the BIN issue may take a look at the PR in action:
  * https://dit-tests.web.app
2023-09-19 22:38:51 +00:00
derdilla
5467363306
Cover some Services tests with leak tracing (#134381) 2023-09-14 11:36:55 -07:00
Polina Cherkasova
834f5dc296
RestorationManager should dispatch creation in constructor. (#133911) 2023-09-08 15:05:43 -07:00
yaakovschectman
e6e44de33c
Add MacOS AppKitView class. (#132583)
Add derived classes from the Darwin platform view base classes for
MacOS. Functionality is largely the same as the `UiKitView`, but the two
are decoupled and and can further diverge in the future as needed. Some
unit tests remain skipped for now as the gesture recognizers for MacOS
are not yet implemented.

https://github.com/flutter/flutter/issues/128519

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat

---------

Co-authored-by: Chris Bracken <chris@bracken.jp>
2023-08-31 17:48:12 -04:00
Mouad Debbar
55fe41be59
[web] New HtmlElementView.fromTagName constructor (#130513)
This wraps up the platform view improvements discussed in https://github.com/flutter/flutter/issues/127030.

- Splits `HtmlElementView` into 2 files that are conditionally imported.
- The non-web version can be instantiated but it throws if it ends up being built in a widget tree.
- Out-of-the-box view factories that create visible & invisible DOM elements given a `tagName` parameter.
- New `HtmlElementView.fromTagName()` constructor that uses the default factories to create DOM elements.
- Tests covering the new API.

Depends on https://github.com/flutter/engine/pull/43828

Fixes https://github.com/flutter/flutter/issues/127030
2023-08-07 23:45:19 +00:00
Martin Kustermann
9c10151508
Use utf8.encode() instead of longer const Utf8Encoder.convert() (#130567)
The change in [0] has propagated now everywhere, so we can use
`utf8.encode()` instead of the longer `const Utf8Encoder.convert()`.

Also it cleans up code like

```
  TypedData bytes;
  bytes.buffer.asByteData();
```

as that is not guaranteed to be correct, the correct version would be

```
  TypedData bytes;
  bytes.buffer.asByteData(bytes.offsetInBytes, bytes.lengthInBytes);
```

a shorter hand for that is:

```
  TypedData bytes;
  ByteData.sublistView(bytes);
```

[0] https://github.com/dart-lang/sdk/issues/52801
2023-07-24 11:26:05 +02:00
Ian Hickson
d21109220b
Catch errors in loadStructuredData (#130748)
Fixes https://github.com/flutter/flutter/issues/42390
2023-07-18 23:02:56 +00:00
Michael Goderbauer
55b6f049a6
Enable unreachable_from_main lint - it is stable now!!1 (#129854)
PLUS: clean-up of all the unreachable stuff.
2023-07-06 00:09:01 +00:00
Mouad Debbar
b0188cd182
[web] Pass creation params to the platform view factory (#128146)
This concludes step 1 of the `HtmlElementView` improvements. It's now possible to pass creation params to platform view factories directly from `HtmlElementView`.

Here's a sample app using a single factory to render platform views in different colors:

<details>
  <summary>Code sample</summary>
  
  ```dart
import 'dart:js_interop';
import 'dart:ui_web' as ui_web;
import 'package:flutter/material.dart';
import 'package:web/web.dart' as web;

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Platform View Demo',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Platform View Demo'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              BoxWrapper('red'),
              BoxWrapper(null),
              BoxWrapper('blue'),
            ],
          ),
        ),
      ),
    );
  }
}

bool isRegistered = false;

class BoxWrapper extends StatelessWidget {
  const BoxWrapper(this.cssColor);

  final String? cssColor;

  void register() {
    if (isRegistered) return;
    isRegistered = true;

    ui_web.platformViewRegistry.registerViewFactory('my-platform-view', (
      id, {
      Object? params,
    }) {
      params as String?;

      final element = web.document.createElement('div'.toJS) as web.HTMLElement;
      element.textContent = 'Platform View'.toJS;
      element.style
        ..lineHeight = '100px'.toJS
        ..fontSize = '24px'.toJS
        ..backgroundColor = (params ?? 'pink').toJS
        ..textAlign = 'center'.toJS;
      return element;
    });
  }

  @override
  Widget build(BuildContext context) {
    register();
    return SizedBox(
      width: 200,
      height: 100,
      child: Card(
        child: HtmlElementView(
          viewType: 'my-platform-view',
          creationParams: cssColor,
        ),
      ),
    );
  }
}
  ```
</details>

![image](https://github.com/flutter/flutter/assets/1278212/4b62ed8b-2314-49d6-9b4a-5da849bf2a48)

Depends on https://github.com/flutter/engine/pull/42255

Part of https://github.com/flutter/flutter/issues/127030
2023-06-15 18:00:25 +00:00
Andrew Kolos
cfe4fedca2
rename generated asset manifest file back to AssetManifest.bin (from AssetManifest.smcbin) (#128529)
Closes https://github.com/flutter/flutter/issues/128456, which is now linked to in a code comment in this change.
Reopens https://github.com/flutter/flutter/issues/124883.

This effectively reverts https://github.com/flutter/flutter/pull/126077 and is intended to be cherry-picked into stable.
2023-06-09 21:20:50 +00:00
Greg Spencer
a280346193
Add AppLifecycleListener, with support for application exit handling (#123274)
## Description

This adds `AppLifecycleListener`, a class for listening to changes in the application lifecycle, and responding to requests to exit the application.

It depends on changes in the Engine that add new lifecycle states: https://github.com/flutter/engine/pull/42418

Here's a diagram for the lifecycle states. I'll add a similar diagram to the documentation for these classes.

![Application Lifecycle Diagram](https://github.com/flutter/flutter/assets/8867023/f6937002-cb93-4ab9-a221-25de2c45cf0e)

## Related Issues
 - https://github.com/flutter/flutter/issues/30735

## Tests
- Added tests for new lifecycle value, as well as for the `AppLifecycleListener` itself.
2023-06-08 22:57:19 +00:00
Andrew Kolos
759ebef689
Do not try to load main/default asset image if only higher-res variants exist (#128143)
Fixes https://github.com/flutter/flutter/issues/127090.

https://github.com/flutter/flutter/pull/122505 did a few things to speed up the first asset load that a flutter app performs. One of those things was to not include the main asset in its own list of variants in the asset manifest. The idea was that we know that the main asset always exists, so including it in its list of variants is a waste of storage space and loading time (even if the cost was tiny).

However, the assumption that the main asset always exists is wrong. From [Declaring resolution-aware image assets](https://docs.flutter.dev/ui/assets-and-images#resolution-aware), which predates https://github.com/flutter/flutter/pull/122505:

> Each entry in the asset section of the pubspec.yaml should correspond to a real file, with the exception of the main asset entry. If the main asset entry doesn’t correspond to a real file, then the asset with the lowest resolution is used as the fallback for devices with device pixel ratios below that resolution. The entry should still be included in the pubspec.yaml manifest, however.

For example, it's valid to declare `assets/image.png` as an asset even if only `assets/3x/image.png` exists on disk.

This fix restores older behavior of including a main asset as a variant of itself in the manifest if it exists.

This fix also includes a non-user-visible behavior change:
* `"dpr"` is no longer a required field in the asset manifest's underlying structure. For the main asset entry, we do not include `"dpr"`. It makes less sense for the tool to decide what the default target dpr for an image should be. This should be left to the framework.
2023-06-07 03:19:15 +00:00
Greg Spencer
a257efc284
Fix handling of AppLifecycleState.hidden (#127987)
## Description

This fixes the parsing of `AppLifecycleState` in the services binding so that it knows what it is.

## Related Issues
 - Fixes https://github.com/flutter/flutter/issues/127974

## Tests
 - Added a test that causes parsing of all the different app lifecycle states.
2023-05-31 22:03:06 +00:00
yaakovschectman
130944e785
Alert engine upon registering ServiceBinding (#126075)
Send a platform message to the engine when the `ServiceBinding` is
registered. Framework side of
https://github.com/flutter/engine/pull/41733

Addresses https://github.com/flutter/flutter/issues/126033

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat

---------

Co-authored-by: Greg Spencer <gspencergoog@users.noreply.github.com>
2023-05-16 13:37:12 -04:00
Andrew Kolos
d3e0e03e2e
rename AssetManifest.bin (#126077)
Fixes #124883. Will require a g3fix.

Renames `AssetManifest.bin` to `AssetManifest.smcbin` (madeup extension for "Standard Message Codec binary").
2023-05-15 15:45:09 +00:00
Tomasz Gucio
99c7e9f088
Add spaces after flow control statements (#126320) 2023-05-15 11:07:30 +02:00
Bruno Leroux
e435b1ae26
Add debugPrintKeyboardEvents flag (#125629)
## Description

This PR adds a new debug flag named `debugPrintKeyboardEvents` to help debugging keyboard issues.

Keyboard code has some useful asserts but sometimes an assertion failure is related to the handling of previous key events. This debug flag will help understanding the flow of key events which leads to an assertion failure.

## Related Issue

Fixes https://github.com/flutter/flutter/issues/125627

## Tests

Adds 1 test.
2023-05-02 15:15:07 +00:00
Bruno Leroux
af050d95ae
Add a channel to query the engine keyboard state (#122885)
## Description

This PR adds a new channel to query the engine keyboard state.
See https://github.com/flutter/flutter/issues/87391#issuecomment-1228975571 for motivation. 

## Related Issue

Framework side implementation for https://github.com/flutter/flutter/issues/87391.

Once approved the framework will try to query the initial keyboard state from the engine. PRs will be needed on the engine side to answer the framework query.

## Tests

Adds 1 test.
2023-04-28 21:05:20 +00:00
chunhtai
3b4ac4d5cc
Implement url support for RouteInformation and didPushRouteInformation (#119968)
Related https://github.com/flutter/flutter/issues/100624

The goal is to make sure the engine can send a location string in either the existing format or a complete uri string to the framework, and the framework will still work as usual.
2023-04-24 18:33:24 +00:00
Rexios
bf0bdacb29
[flutter_test] Adds method to mock EventChannels (#124415)
[flutter_test] Adds method to mock EventChannels
2023-04-10 17:02:48 +00:00
Michael Goderbauer
73bd978529
Migrate away from deprecated BinaryMessenger API (#124348)
Migrate away from deprecated BinaryMessenger API
2023-04-07 19:38:52 +00:00
Zachary Anderson
2f4a6afd30
Revert "[flutter_test] Adds method to mock EventChannels" (#124401)
Reverts flutter/flutter#123726

Analysis failures on CI
https://ci.chromium.org/ui/p/flutter/builders/prod/Linux%20analyze/12890/overview
2023-04-07 10:10:00 -07:00
Rexios
f28eb28f0d
[flutter_test] Adds method to mock EventChannels (#123726)
[flutter_test] Adds method to mock EventChannels
2023-04-07 16:12:27 +00:00
Greg Price
a28aae918e
Remove no-shuffle from framework tests, part 1: easy cases (#123751)
Remove no-shuffle from framework tests, part 1: easy cases
2023-03-30 18:28:51 +00:00
Loïc Sharma
70e1dc7387
[Clipboard] Assert at least one clipboard data variant is provided (#122446)
[Clipboard] Assert at least one clipboard data variant is provided
2023-03-24 19:12:10 +00:00
Greg Spencer
bcdab118ba
Add support for application exit requests (#121378)
Add support for application exit requests
2023-03-17 15:35:55 +00:00
Andrew Kolos
313b01658a
Reland "Speed up first asset load by using the binary-formatted asset manifest for image resolution" (#122505)
Reland "Speed up first asset load by using the binary-formatted asset manifest for image resolution"
2023-03-15 18:17:05 +00:00
Jonah Williams
8d4fd89c74
Revert "Reland "Speed up first asset load by using the binary-formatted asset manifest for image resolution (#121322)" (#122449)
Revert "Reland "Speed up first asset load by using the binary-formatted asset manifest for image resolution"
2023-03-11 03:30:06 +00:00
Jami Couch
2a67bf78f0
Add support for iOS UndoManager (#98294)
Add support for iOS UndoManager
2023-03-08 19:45:49 +00:00
Andrew Kolos
57c7aa53c1
Reland "Speed up first asset load by using the binary-formatted asset manifest for image resolution (#121322)
Reland "Speed up first asset load by using the binary-formatted asset manifest for image resolution
2023-03-06 20:37:43 +00:00
Lioness100
26b6c1bedd
Fix typos (#121171)
* Fix typos

* lowercase animated & opacity

* Undo typo fix

---------

Co-authored-by: Michael Goderbauer <goderbauer@google.com>
2023-02-23 19:43:21 +00:00
Ian Hickson
07c548c698
Apply BindingBase.checkInstance to TestDefaultBinaryMessengerBinding (#116937) 2023-02-13 23:55:58 +00:00
Kate Lovett
780c9a8de1
Remove deprecated SystemChrome.setEnabledSystemUIOverlays (#119576) 2023-02-10 14:03:01 -06:00
Gabriel Terwesten
ec289f1eb4
Don't call PlatformViewCreatedCallbacks after AndroidViewController is disposed (#116854)
* Don't call `PlatformViewCreatedCallback`s after `AndroidViewController` is disposed

Before this change it was possible that, if a `AndroidViewController` was disposed before we got the notification that the platform view was created, `PlatformViewCreatedCallback`s where called even after calling `AndroidViewController.dispose`.

Also makes `_PlatformViewLinkState._onPlatformViewCreated` more carful to only call `setState` when mounted.

Closes #84628
Closes #96384

* Allow all widgets to remove listeners from controller

* Remove assert

* Add expectations to test
2023-02-08 18:51:50 +00:00
Andrew Kolos
fd76ef0f26
Reland "Add API for discovering assets" (#119277)
* add asset manifest bin loading and asset manifest api

* use new api for image resolution

* remove upfront smc data casting

* fix typecasting issue

* remove unused import

* fix tests

* lints

* lints

* fix import

* revert image resolution changes

* Update image_resolution_test.dart

* Update decode_and_parse_asset_manifest.dart

* make targetDevicePixelRatio optional

* Update packages/flutter/lib/src/services/asset_manifest.dart

Co-authored-by: Jonah Williams <jonahwilliams@google.com>

* Update packages/flutter/lib/src/services/asset_manifest.dart

Co-authored-by: Jonah Williams <jonahwilliams@google.com>

* fix immutable not being imported

* return List in AssetManifest methods, fix annotation import

* simplify onError callback

* make AssetManifest methods abstract instead of throwing UnimplementedError

* simplify AssetVariant.key docstring

* tweak _AssetManifestBin docstring

* make AssetManifest and AssetVariant doc strings more specific

* use List.of instead of List.from for type-safety

* adjust import

* change _AssetManifestBin comment from doc comment to normal comment

* revert to callback function for onError in loadStructuredBinaryData

* add more to the docstring of AssetManifest.listAssets and AssetVariant.key

* add tests for CachingAssetBundle caching behavior

* add simple test to ensure loadStructuredBinaryData correctly calls load

* Update asset_manifest.dart

* update docstring for AssetManifest.getAssetVariants

* rename getAssetVariants, have it include main asset

* rename isMainAsset field of AssetMetadata to main

* (slightly) shorten name of describeAssetAndVariants

* rename describeAssetVariants back to getAssetVariants

* add tests for TestAssetBundle

* nits

* fix typo in docstring

* remove no longer necessary non-null asserts

* update gallery and google_fonts versions

---------

Co-authored-by: Jonah Williams <jonahwilliams@google.com>
2023-02-02 15:17:15 +00:00