Commit graph

1416 commits

Author SHA1 Message Date
Nate c53a18f4e4
Implementing null-aware operators throughout the repository (#143804)
This pull request fixes #143803 by taking advantage of Dart's null-aware operators.

And unlike `switch` expressions ([9 PRs](https://github.com/flutter/flutter/pull/143634) and counting), the Flutter codebase is already fantastic when it comes to null-aware coding. After refactoring the entire repo, all the changes involving `?.` and `??` can fit into a single pull request.
2024-02-23 19:02:22 +00:00
Qun Cheng 4715216c01
Revert "Introduce tone-based surfaces and accent color add-ons - Part 2" (#143973)
Reverts flutter/flutter#138521
2024-02-22 14:51:28 -08:00
Derek Xu dfb5888e8f
Support using lightweight Flutter Engines to run tests (#141726)
This PR implements the functionality described above and hides it behind
the `--experimental-faster-testing` flag of `flutter test`.

### The following are some performance measurements from test runs
conducted on GitHub Actions

run 1 logs:
https://github.com/derekxu16/flutter_test_ci/actions/runs/8008029772/attempts/1
run 2 logs:
https://github.com/derekxu16/flutter_test_ci/actions/runs/8008029772/attempts/2
run 3 logs:
https://github.com/derekxu16/flutter_test_ci/actions/runs/8008029772/attempts/3

**length of `flutter test --reporter=expanded test/animation
test/foundation` step**

run 1: 54s
run 2: 52s
run 3: 56s

average: 54s

**length of `flutter test --experimental-faster-testing
--reporter=expanded test/animation test/foundation` step**

run 1: 27s
run 2: 27s
run 3: 29s

average: 27.67s (~48.77% shorter than 54s)

**length of `flutter test --reporter=expanded test/animation
test/foundation test/gestures test/painting test/physics test/rendering
test/scheduler test/semantics test/services` step**

run 1: 260s
run 2: 270s
run 3: 305s

average: 278.33s


**length of `flutter test --experimental-faster-testing
--reporter=expanded test/animation test/foundation test/gestures
test/painting test/physics test/rendering test/scheduler test/semantics
test/services` step**

from a clean build (right after deleting the build folder):

run 1: 215s
run 2: 227s
run 3: 245s

average: 229s (~17.72% shorter than 278.33s)

Note that in reality, `test/material` was not passed to `flutter test`
in the trials below. All of the test files under `test/material` except
for `test/material/icons_test.dart` were listed out individually

**length of `flutter test --reporter=expanded test/material` step**

run 1: 408s
run 2: 421s
run 3: 451s

average: 426.67s

**length of `flutter test --experimental-faster-testing
--reporter=expanded test/material` step**

run 1: 382s
run 2: 373s
run 3: 400s

average: 385s (~9.77% shorter than 426.67s)

---------

Co-authored-by: Dan Field <dnfield@google.com>
2024-02-22 13:32:29 -05:00
Qun Cheng a2c7ed95d1
Introduce tone-based surfaces and accent color add-ons - Part 2 (#138521)
This PR is to introduce 19 new color roles and deprecate 3 color roles in `ColorScheme`.
**Tone-based surface colors** (7 colors): 
* surfaceBright
* surfaceDim
* surfaceContainer
* surfaceContainerLowest
* surfaceContainerLow
* surfaceContainerHigh
* surfaceContainerHighest

**Accent color add-ons** (12 colors):
* primary/secondary/tertiary-Fixed
* primary/secondary/tertiary-FixedDim
* onPrimary/onSecondary/onTertiary-Fixed
* onPrimary/onSecondary/onTertiary-FixedVariant

**Deprecated colors**:
* background -> replaced with surface
* onBackground -> replaced with onSurface
* surfaceVariant -> replaced with surfaceContainerHighest

Please checkout this [design doc](https://docs.google.com/document/d/1ODqivpM_6c490T4j5XIiWCDKo5YqHy78YEFqDm4S8h4/edit?usp=sharing) for more information:)

![Screenshot 2024-01-08 at 4 56 51 PM](https://github.com/flutter/flutter/assets/36861262/353cdb4c-6ba9-4435-a518-fd3f67e415f0)
2024-02-20 19:01:50 +00:00
Michael Goderbauer 546bdec7ef
Fix implementation imports outside of lib (#143594)
Work towards https://github.com/dart-lang/linter/issues/4859

There are libraries outside a `lib/` directory, which violate `implementation_imports`.

Supersedes https://github.com/flutter/flutter/pull/143560.
2024-02-16 22:38:10 +00:00
Michael Goderbauer 50862bc04a
Fix SemanticsFinder for multi-view (#143485)
Fixes https://github.com/flutter/flutter/issues/143405.

It was counter-intuitive that a SemanticsFinder without specifying a FlutterView would only search the nodes in the default view. This change makes it so that when no view is specified the semantics trees of all known FlutterViews are searched.
2024-02-16 22:24:55 +00:00
Kate Lovett ea3d066237
Reland simulatedAccessibilityTraversal fix (#143527)
Relands https://github.com/flutter/flutter/pull/143386
Which was reverted in https://github.com/flutter/flutter/pull/143523
Fixes https://github.com/flutter/flutter/issues/143173
Unblocks https://github.com/flutter/flutter/pull/143485

⭐ ➡️  Update from the revert is in this commit: 1e6853291e
2024-02-15 21:37:40 +00:00
auto-submit[bot] d00fe8faae
Reverts "Fix and test SemanticsController.simulatedAccessibilityTraversal (#143386)" (#143523)
Reverts flutter/flutter#143386

Initiated by: Piinks

Reason for reverting: This broke a customer test.

Original PR Author: Piinks

Reviewed By: {goderbauer}

This change reverts the following previous change:
Original Description:
Fixes https://github.com/flutter/flutter/issues/143173

The `start` and `end` parameters of `SemanticsController.simulatedAccessibilityTraversal` were deprecated in https://github.com/flutter/flutter/issues/112413, but no tests were added that verified the new API. 😳

This change
- fixes a typo in an error message
- fixes the new `startNode` and `endNode` not being accounted for in setting the traversal range
- adds dart fixes for the deprecations
- adds tests for the new API that is meant to replace the deprecated one.
  - Filed https://github.com/flutter/flutter/issues/143405 to follow up on the new API not working in multiple views.
2024-02-15 15:49:26 +00:00
auto-submit[bot] 0fac13b443
Reverts "[a11y] Add isEnabled semantics flag to text field (#143334)" (#143494)
Reverts flutter/flutter#143334

Initiated by: hangyujin

Reason for reverting: broke g3 tests

Original PR Author: hangyujin

Reviewed By: {LongCatIsLooong}

This change reverts the following previous change:
Original Description:
Add a semantics flag to   text field to fix https://github.com/flutter/flutter/issues/143337 (in IOS the disabled text field is not read `dimmed`)

internal: b/322345393
2024-02-14 22:43:18 +00:00
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
Kate Lovett f190d6259f
Fix and test SemanticsController.simulatedAccessibilityTraversal (#143386)
Fixes https://github.com/flutter/flutter/issues/143173

The `start` and `end` parameters of `SemanticsController.simulatedAccessibilityTraversal` were deprecated in https://github.com/flutter/flutter/issues/112413, but no tests were added that verified the new API. 😳

This change
- fixes a typo in an error message
- fixes the new `startNode` and `endNode` not being accounted for in setting the traversal range
- adds dart fixes for the deprecations
- adds tests for the new API that is meant to replace the deprecated one.
  - Filed https://github.com/flutter/flutter/issues/143405 to follow up on the new API not working in multiple views.
2024-02-14 20:48:36 +00:00
hangyu 14bce28f3c
[a11y] Add isEnabled semantics flag to text field (#143334)
Add a semantics flag to   text field to fix https://github.com/flutter/flutter/issues/143337 (in IOS the disabled text field is not read `dimmed`)

internal: b/322345393
2024-02-13 22:35:43 +00:00
Polina Cherkasova b48dfca382
Upgrade leak_tracker. (#143236) 2024-02-09 14:41:22 -08:00
Kris Pypen 2f117c545b
Fix: performance improvement on golden test comparison (#142913)
During golden test image comparison 2 lists of a different type are compared with the method "identical", so this will never be true. The test image is a _Uint8ArrayView while the master image is an Uint8List. So that results in always a heavy computation to get the difference between the test and the master image.

When you run this test snippet I go from 51 seconds to 14 seconds:
```dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  for (int i = 0; i < 100; i++) {
    testWidgets('Small test', (WidgetTester tester) async {
      await tester.pumpWidget(Directionality(textDirection: TextDirection.ltr, child: Text('jo')));
      await expectLater(find.byType(Text), matchesGoldenFile('main.png'));
    });
  }
}
```
2024-02-09 22:05:00 +00:00
Valentin Vignal ab836a2db0
Add the number of mismatched pixels to golden tests output (#142975)
Fixes https://github.com/flutter/flutter/issues/141036
2024-02-07 18:59:57 +00:00
Andrew Brampton 10f1e63579
Update _goldens_io.dart to generate failure images during a size mism… (#142177)
Update the `matchesGoldenFile()` / `LocalComparisonOutput` code to generate failure images for golden tests that fail when the image sizes do not match. This can make it far quicker to identify what is wrong with the test image.

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

- [ x I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
2024-02-07 03:23:29 +00:00
Christopher Fujino a80333349a
Unpin test (#141427)
Fixes https://github.com/flutter/flutter/issues/140169
2024-02-01 18:53:23 +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
Michael Goderbauer 671d8eaf71
Relands "Add runWidget to bootstrap a widget tree without a default View" (#142344)
Reverts flutter/flutter#142339

In the original change one of the tests included the same view twice which resulted in a different failure than the expected one. The second commit contains the fix for this. I don't understand how this wasn't caught presubmit on CI.
2024-01-26 23:05:53 +00:00
auto-submit[bot] 114261a63a
Reverts "Add runWidget to bootstrap a widget tree without a default View" (#142339)
Reverts flutter/flutter#141484
Initiated by: eliasyishak
This change reverts the following previous change:
Original Description:
The existing `runApp` bootstraps the widget tree and renders the provided widget into the default view (which is currently the implicit View from `PlatformDispatcher.implicitView` and - in the future - may be a default-created window). Apps, that want more control over the View they are rendered in, need a new way to bootstrap the widget tree: `runWidget`. It does not make any assumptions about the View the provided widget is rendered into. Instead, it is up to the caller to include a View widget in the provided widget tree that specifies where content should be rendered. In the future, this may enable developers to create a custom window for their app instead of relying on the default-created one.
2024-01-26 21:06:27 +00:00
Michael Goderbauer 5b44596c5f
Add runWidget to bootstrap a widget tree without a default View (#141484)
The existing `runApp` bootstraps the widget tree and renders the provided widget into the default view (which is currently the implicit View from `PlatformDispatcher.implicitView` and - in the future - may be a default-created window). Apps, that want more control over the View they are rendered in, need a new way to bootstrap the widget tree: `runWidget`. It does not make any assumptions about the View the provided widget is rendered into. Instead, it is up to the caller to include a View widget in the provided widget tree that specifies where content should be rendered. In the future, this may enable developers to create a custom window for their app instead of relying on the default-created one.
2024-01-26 19:12:21 +00:00
Polina Cherkasova a522b38e96
Upgrade leak_tracker. (#142162) 2024-01-24 15:33:17 -08:00
Jesús S Guerrero b5262f0d80
Revert "[web] - Fix broken TextField in semantics mode when it's a sibling of Navigator" (#142129)
Reverts flutter/flutter#138446

b/322136071
2024-01-24 16:13:26 +00:00
Hassan Toor 59e892d391
[web] - Fix broken TextField in semantics mode when it's a sibling of Navigator (#138446)
When a `TextField` is rendered before a `Navigator`, it breaks in semantics mode.  This is because the framework generates the incorrect semantics tree (excludes the TextField) and when that tree gets sent to the engine, we don't get the signal to create the corresponding `<input>` element.

This happens for a few reasons:
* `ModalBarrier` uses `BlockSemantics` to drop the semantics of routes beneath the current route in `Navigator`
* `ModalBarrier` mistakenly recognizes the widget outside of the `Navigator` to be its sibling
*  So we end up dropping the semantics node of the `TextField` rendered before it. 

The fix is to let `Navigator` generate a semantics node so that `ModalBarrier` doesn't mistakenly think widgets outside of `Navigator` are its siblings.  

`Navigator` doesn't currently do this, which causes all the nodes generated from its widget subtree to be directly attached to the parent semantics node above `Navigator` - since this is also the parent of `TextField`, it considers them siblings. 

Fixes https://github.com/flutter/flutter/issues/129324
2024-01-22 17:03:14 +00:00
Michael Goderbauer cc544169be
Make pumpWidget's arguments named (#141728)
Much nicer calling API and simplifies evolving this API in the future.

I wish we could write a dart fix for this, but that's blocked on https://github.com/dart-lang/sdk/issues/54668.
2024-01-19 18:29:07 +00:00
fzyzcjy 9e024fdf31
Tiny fix inaccurate documentations about bindings (#140282)
The old doc says that, AutomatedTestWidgetsFlutterBinding for `flutter test` and LiveTestWidgetsFlutterBinding for `flutter run`. However, suppose we `flutter test integration_test/simple_test.dart` with the following code:

```
void main() {
  testWidgets('hi', (WidgetTester tester) async {
    print('hi ${TestWidgetsFlutterBinding.instance} ${Platform.operatingSystem}');
  });
}
```

We will see: `hi <IntegrationTestWidgetsFlutterBinding> ios`. Therefore, we see `IntegrationTestWidgetsFlutterBinding` is used in a `flutter test` command, which is contrary to the documentation.
2024-01-19 17:45:13 +00:00
Polina Cherkasova a8e699249b
Ignore or fix leaks. (#141468) 2024-01-16 09:44:49 -08:00
Anis Alibegić 81d80c587d
Fixed a lot of typos (#141431)
Fair amount of typos spotted and fixed. Some of them are in comments, some of them are in code and some of them are in nondart files.

There is no need for issues since it's a typo fix.

I have doubts about [packages/flutter_tools/lib/src/ios/core_devices.dart](https://github.com/flutter/flutter/compare/master...anisalibegic:flutter:master#diff-fdbc1496b4bbe7e2b445a567fd385677af861c0093774e3d8cc460fdd5b794fa), I have a feeling it might broke some things on the other end, even though it's a typo.
2024-01-12 22:10:25 +00:00
Polina Cherkasova 34f1f5f19e
Improve testing for leak tracking. (#140553) 2024-01-10 11:04:28 -08:00
Polina Cherkasova 0f2618ff4f
Fix or except leaks. (#141081)
Contributes to https://github.com/flutter/devtools/issues/6909.
2024-01-10 00:17:33 +00:00
Michael Goderbauer 4534a24c09
Reapply "Dynamic view sizing" (#140165) (#140918)
This reverts commit
d24c01bd0c.

The original change was reverted because it caused some apps to get
stuck on the splash screen on some phones.

An investigation determined that this was due to a rounding error.
Example: The device reports a physical size of 1008.0 x 2198.0 with a
dpr of 1.912500023841858. Flutter would translate that to a logical size
of 527.0588169589221 x 1149.2810314243163 and use that as the input for
its layout algorithm. Since the constraints here are tight, the layout
algorithm would determine that the resulting logical size of the root
render object must be 527.0588169589221 x 1149.2810314243163.
Translating this back to physical pixels by applying the dpr resulted in
a physical size of 1007.9999999999999 x 2198.0 for the frame. Android
now rejected that frame because it didn't match the expected size of
1008.0 x 2198.0 and since no frame had been rendered would never take
down the splash screen.

Prior to dynamically sized views, this wasn't an issue because we would
hard-code the frame size to whatever the requested size was.

Changes in this PR over the original PR:

* The issue has been fixed now by constraining the calculated physical
size to the input physical constraints which makes sure that we always
end up with a size that is acceptable to the operating system.
* The `ViewConfiguration` was refactored to use the slightly more
convenient `BoxConstraints` over the `ViewConstraints` to represent
constraints. Both essentially represent the same thing, but
`BoxConstraints` are more powerful and we avoid a couple of translations
between the two by translating the` ViewConstraints` from the
`FlutterView` to `BoxConstraints` directly when the `ViewConfiguration`
is created.

All changes over the original PR are contained in the second commit of
this PR.

Fixes b/316813075
Part of https://github.com/flutter/flutter/issues/134501.
2024-01-09 14:10:43 -08:00
Polina Cherkasova 1f3103e50d
Upgrade leak_tracker. (#141153) 2024-01-09 12:02:35 -08:00
Polina Cherkasova 188d4d1fdf
Remove conditions that depend on order. (#141183) 2024-01-09 11:19:04 -08:00
Zachary Anderson 7859fe3b24
Disable test shuffling in widget_tester_leaks_test.dart (#141110)
Fails with `flutter test --test-randomize-ordering-seed=20240108`

https://ci.chromium.org/ui/p/flutter/builders/prod/Linux%20framework_tests_misc/15044/overview

cc @polina-c
2024-01-08 15:54:05 +00:00
Polina Cherkasova 3ed0399663
Reland "integrate testWidgets with leak tracking" (#140521) (#140928) 2024-01-04 10:20:36 -08:00
auto-submit[bot] 253dc6f847
Reverts "Re-land integrate testWidgets with leak tracking." (#140926)
Reverts flutter/flutter#140521
Initiated by: zanderso
This change reverts the following previous change:
Original Description:
Original PR: https://github.com/flutter/flutter/pull/138057
Revert: https://github.com/flutter/flutter/pull/140502
Issue: https://ci.chromium.org/ui/p/flutter/builders/prod/Linux_android%20flutter_test_performance/12787/overview
Exception: flutter test rendered unexpected output (1 bad lines)
Explanation: leak tracker adds tear down even when there is no leak tracking, because at the moment of adding tear down it is unclear if leak tracking will be used for some tests.
Fix: add enabling flag for leak tracker and make creation of tear down conditional.
Prerequisites:
2024-01-03 22:36:17 +00:00
Polina Cherkasova baf6ba134f
Re-land integrate testWidgets with leak tracking. (#140521) 2024-01-03 12:21:08 -08:00
Elliott Brooks 55ba27d3bc
Link to wiki page about updating dependencies in each pubspec.yaml file (#140826)
Added a minimal wiki page about how to use the `update-packages` tool: https://github.com/flutter/flutter/wiki/Updating-dependencies-in-Flutter

This PR adds a link to that wiki page at the top of each pubspec.yaml file
2024-01-03 18:28:52 +00:00
Polina Cherkasova 45c611f040
Upgrade leak_tracker. (#140758) 2024-01-02 20:58:16 +00:00
Jim Graham 8407dd2d0e
Revert "Integrate testWidgets with leak tracking. (#138057)" (#140502)
The PR is breaking the `flutter_test_performance` test and making the
tree red.
2023-12-21 12:44:58 +01:00
Polina Cherkasova d746007fcd
Integrate testWidgets with leak tracking. (#138057)
Contributes to: https://github.com/flutter/flutter/issues/135856

TODO:
2023-12-21 00:19:59 +00:00
flutter-pub-roller-bot 2d75f76b44
Roll pub packages (#140472)
This PR was generated by `flutter update-packages --force-upgrade`.
2023-12-20 22:57:21 +00:00
Michael Goderbauer 68e346e41c
Remove outdated ignores from tool (#140467)
These were not ignoring anything (anymore).
2023-12-20 22:14:32 +00:00
LongCatIsLooong e2e8bcb1bc
Reland find.textRange.ofSubstring changes (#140469)
Extracted from https://github.com/flutter/flutter/pull/139717 as-is. Landing this change first so we can avoid doing a g3fix.
2023-12-20 22:00:55 +00:00
auto-submit[bot] 9003f13803
Reverts "Make TextSpan hit testing precise." (#140468)
Reverts flutter/flutter#139717
Initiated by: LongCatIsLooong
This change reverts the following previous change:
Original Description:
Fixes https://github.com/flutter/flutter/issues/131435, #104594, #43400
Needs https://github.com/flutter/engine/pull/48774 (to fix the web test failure).

Currently the method we use for text span hit testing `TextPainter.getPositionForOffset` always returns the closest `TextPosition`, even when the given offset is far away from the text. 

The new TextPaintes method tells you the layout bounds (`width =  letterspacing / 2 + x_advance + letterspacing / 2`, `height = font ascent + font descent`) of a character, the PR changes the hit testing implementation such that a TextSpan is only considered hit if the point-down event landed in one of it's character's layout bounds.

Potential issues:

1. In theory since the text is baseline aligned, we should use the max ascent and max descent of each character to calculate the height of the text span's hit-test region, in case some characters in the span have to fall back to a different font, but that will be slower and it typically doesn't make a huge difference. 

This is a breaking change. It also introduces a new finder and a new method `WidgetTester.tapOnText`: `await tester.tapOnText('string to match')` for ease of migration.
2023-12-20 19:32:10 +00:00
LongCatIsLooong ea5b97286e
Make TextSpan hit testing precise. (#139717)
Fixes https://github.com/flutter/flutter/issues/131435, #104594, #43400
Needs https://github.com/flutter/engine/pull/48774 (to fix the web test failure).

Currently the method we use for text span hit testing `TextPainter.getPositionForOffset` always returns the closest `TextPosition`, even when the given offset is far away from the text. 

The new TextPaintes method tells you the layout bounds (`width =  letterspacing / 2 + x_advance + letterspacing / 2`, `height = font ascent + font descent`) of a character, the PR changes the hit testing implementation such that a TextSpan is only considered hit if the point-down event landed in one of it's character's layout bounds.

Potential issues:

1. In theory since the text is baseline aligned, we should use the max ascent and max descent of each character to calculate the height of the text span's hit-test region, in case some characters in the span have to fall back to a different font, but that will be slower and it typically doesn't make a huge difference. 

This is a breaking change. It also introduces a new finder and a new method `WidgetTester.tapOnText`: `await tester.tapOnText('string to match')` for ease of migration.
2023-12-20 03:23:29 +00:00
Polina Cherkasova 6368d65622
Upgrade to version of leak tracker that does not depend on test_widgets. (#140247)
Contributes to: https://github.com/flutter/flutter/issues/135856
2023-12-19 04:28:09 +00:00
Bartek Pacia 8c02a22403
Use SemanticsUpdateBuilder again, remove all references to temporary SemanticsUpdateBuilderNew (#139942)
This PR removes all usages of the temporary `SemanticsUpdateBuilderNew` API in favor of `SemanticsUpdateBuilder`. These two APIs are the same as of now.

This is mainly targeted at https://github.com/flutter/flutter/issues/17988

Steps:
part 1: [engine] add `SemanticsUpdateBuilderNew` https://github.com/flutter/engine/pull/47961
part 2: [flutter] use `SemanticsUpdateBuilderNew` https://github.com/flutter/flutter/pull/138331
part 3: [engine] update `SemanticsUpdateBuilder` to be the same as `SemanticsUpdateBuilderNew` https://github.com/flutter/engine/pull/48882
**part 4: [flutter] use (now updated) `SemanticsUpdateBuilder` again** <-- we are here
part 5: [engine] remove `SemanticsBuilderNew`
2023-12-16 15:23:24 +00:00
Polina Cherkasova baf739c8e6
Remove usage of testWidgetsWithLeakTracking. (#140239) 2023-12-15 14:13:31 -08:00
Polina Cherkasova bda158adf0
Reorganize dependencies on leak_tracker. (#140233)
1. Move leak_tracker and leak_tracker_testing out of direct dependencies.
2. Move leak_tracker_flutter_testing from dev to prod dependencies for flutter_test

It is prerequisite for https://github.com/flutter/flutter/issues/135856
2023-12-15 19:33:23 +00:00