Decoupling recreate#11887
Conversation
…aterial-and-cupertino-and-fixes Copy over the following code from flutter/flutter: - Material - Cupertino - Tests for both. - Examples and their tests for both. - Dart fixes and their tests for both.
This is the result of squashing all commits I made after copying over the flutter/flutter code. The reason for squashing this is that the flutter/flutter code must be merged to main via a merge commit in order to retain all of the history, and I don't want to pollute that history with a bunch of my annoying commits. Move all copied code to its correct location. Material exports Cupertino imports. Also, fix some relative imports in Cupertino by making them import via package. Set up material_ui_examples package. All example tests pass Fix material_ui_examples readme paths Set up cupertino_ui_examples package. All cupertino example tests pass. Fixed dependency from old flutter_api_examples to new cupertino_ui_examples. material_ui import cupertino_ui in main code publish_to: none material_ui_examples references new packages correctly, and tests pass. cupertino_ui_examples references new packages correctly, and tests pass. material_ui test directory organization I think the conflicts were files that were added with a freeze override since I last tried this PR. Additional files for fix_data and test_fixes directories material_ui tests import material_ui/material_ui.dart. Doc import from material.dart to material_ui.dart Test fixes import material_ui/material_ui.dart. Imports updated in material_ui dart fixes. One was deleted because its dart fix is actually in widgets, not material. Imports updated in cupertino_ui dart fixes. drag_target deleted because it is widgets-only. Many widgets-only fixes were removed from cupertino.dart. Migrate cupertino imports in cupertino_ui tests Same tests pass as before. Migrate docImports of Material in cupertino_ui. material_ui tests import cupertino_ui correctly. Skip cupertino_ui test files that fail due to cross imports. Skip cupertino_ui test files that fail due to cross imports. Match main formatting difference with flutter/flutter. Fix duplicate publish_to Cupertino test directory structure matches material's Move examples to the canonical location. Per @chunhtai. Following the example of go_router. Clean up a path dependency. Was expecting to be inside the flutter/flutter repo directory structure. Correct path for example workspace Fix failure due to flutter_test's byTooltip finder. flutter_test uses flutter/material.dart, and the byTooltip finder does `is Tooltip`. Because this package's Tooltip and flutter/material.dart's Tooltip are not the same thing, that check was always returning false. Correct license header for flutter/packages in material_ui. Correct license header for flutter/packages in cupertino_ui. Language annotations on code blocks in readmes CI config files Exclude test_fixes directories from analyzer. As is done in flutter/flutter currently. Don't analyze test files that have been skipped due to cross imports. Fix cupertino_ui analyzer errors Mostly missing dependencies. Fix material_ui analyzer errors, except for import alphabetizing Fix material_ui analyzer import statement alphabetization. Use version of vector_math from the code freeze, not now. Packages should depend on 3.44.0 and above. The first stable release with the frozen Material/Cupertino code. Fix analyzer issues for cupertino_ui. These don't appear locally for some reason, only on CI. I'm concerned about adding all of these awaits. I worry some tests might not complete. analyzer errors in material_ui. dart format . Now the analysis_options.yaml should be totally in sync with flutter/flutter. Revert "dart format ." This reverts commit 536bda6. Repo-wide format on master. Command: dart ./script/tool/bin/flutter_plugin_tools.dart format There were some changes in other packages that I ignored. No batch for now until post 1.0.0. Correct dart version for sdk version. Exceptions for clock and material_color_utilities dart fix --apply It looks like it fixed even more stuff than was showing up on CI. We'll see if that triggers analyzer warnings or not. Revert "dart fix --apply" This reverts commit cf2c83f. This resulted in even more errors in CI. I will manually make the code changes to pass CI. I think that's all cupertino_ui analyzer warnings. Done by hand. All CI analyze errors should be fixed, thanks for Gemini. It actually terminated early but it looks like it touched every file at least. Fix analyzer failures from CI. Manually, just by looking at CI errors on Luci. The one last analyzer issue? Formatting from repo_checks CI check. All I did was open these files in my editor and let it autoformat them, which looks like it should be doing exactly what CI is telling me to do. Fix repo check for minimum allowable dart version. Test: Do we still have to await everything? Given the recent changes updating analysis_options, let's see if the analyzer passes if I don't await this. Fix timeouts caused by new awaits in cupertino_ui. I put these awaits in naively to work around analyzer failures. They should have been unawaited instead. Things I unawaited: Navigator.push (many) Navigator.pushNamed (many) AnimationController.forward (only 1) Fix timeouts caused by new awaits in material_ui. Same as the cupertino commit before this. Undo repo-wide changes, to do in a separate PR and then update this PR. The point is to avoid triggering the CI logic that runs all tests. Some missing formatting. Fix example test failures happening on web. One was due to a platform quirk of web dropping the ".0" from "0.0" on web. In the other, state restoration seemed to not work at all. I found an old issue about it and cases in other tests where it is skipped on web. Move skipped tests to a temporary directory. These tests have compile errors in them. It seemed like we didn't need to move them since I skipped them in analysis_options.dart, but when running `flutter test --platform=chrome`, it did try to compile them, even though other platforms did not. So I had to move them. No more `final` in parameter lists. Not sure how this was missed when everything else was migrated. WIP Fix web example tests Failing due to platform inconsistencies. I fixed some of these before but somehow missed these ones. Formatting Skip menu anchor and chip tests failing on web. Not sure why they don't work, whether it's a bug or a platform difference that the test should accommodate. I've created an issue for each and linked to them.
There was a problem hiding this comment.
Code Review
This pull request decouples the Cupertino library by introducing the cupertino_ui package, which includes a comprehensive set of API examples, corresponding widget tests, configuration files, and data-driven fix definitions. Additionally, cupertino_ui.dart is updated to export individual widget implementations from the src/ directory. The review feedback recommends replacing several usages of the deprecated withOpacity method with withValues across multiple widget files to prevent precision loss.
| WidgetStateProperty<Color> get _defaultFillColor { | ||
| return WidgetStateProperty.resolveWith((Set<WidgetState> states) { | ||
| if (states.contains(WidgetState.disabled)) { | ||
| return CupertinoColors.white.withOpacity(0.5); |
|
|
||
| final Color effectiveFocusOverlayColor = | ||
| widget.focusColor ?? | ||
| HSLColor.fromColor(effectiveActiveColor.withOpacity(kCupertinoFocusColorOpacity)) |
| ..color = brightness == Brightness.light | ||
| ? CupertinoColors.black.withOpacity(_kPressedOverlayOpacity) | ||
| : CupertinoColors.white.withOpacity(_kPressedOverlayOpacity); |
There was a problem hiding this comment.
The withOpacity method is deprecated in Flutter. Use withValues(alpha: _kPressedOverlayOpacity) instead to avoid precision loss.
final pressedPaint = Paint()
..color = brightness == Brightness.light
? CupertinoColors.black.withValues(alpha: _kPressedOverlayOpacity)
: CupertinoColors.white.withValues(alpha: _kPressedOverlayOpacity);| data: CupertinoUserInterfaceLevelData.base, | ||
| child: CupertinoTheme( | ||
| data: effectiveThemeData, | ||
| child: DefaultSelectionStyle( |
| ?.withOpacity( | ||
| widget._style == _CupertinoButtonStyle.tinted | ||
| ? CupertinoTheme.brightnessOf(context) == Brightness.light | ||
| ? kCupertinoButtonTintedOpacityLight | ||
| : kCupertinoButtonTintedOpacityDark | ||
| : widget.color?.opacity ?? 1.0, | ||
| ); |
There was a problem hiding this comment.
The withOpacity method is deprecated in Flutter. Use withValues(alpha: ...) instead to avoid precision loss.
?.withValues(
alpha: widget._style == _CupertinoButtonStyle.tinted
? CupertinoTheme.brightnessOf(context) == Brightness.light
? kCupertinoButtonTintedOpacityLight
: kCupertinoButtonTintedOpacityDark
: widget.color?.opacity ?? 1.0,
);| (backgroundColor ?? CupertinoColors.activeBlue).withOpacity( | ||
| kCupertinoFocusColorOpacity, | ||
| ), |
| bool _childHasFocus = false; | ||
|
|
||
| Color get _effectiveFocusOutlineColor => | ||
| HSLColor.fromColor(CupertinoColors.activeBlue.withOpacity(kCupertinoFocusColorOpacity)) |
| (widget.focusColor ?? CupertinoColors.activeBlue).withOpacity( | ||
| CupertinoTheme.brightnessOf(context) == Brightness.light | ||
| ? kCupertinoButtonTintedOpacityLight | ||
| : kCupertinoButtonTintedOpacityDark, | ||
| ), |
There was a problem hiding this comment.
The withOpacity method is deprecated in Flutter. Use withValues(alpha: ...) instead to avoid precision loss.
(widget.focusColor ?? CupertinoColors.activeBlue).withValues(
alpha: CupertinoTheme.brightnessOf(context) == Brightness.light
? kCupertinoButtonTintedOpacityLight
: kCupertinoButtonTintedOpacityDark,
),| /// | ||
| /// This parameters defaults to false. | ||
| final bool isDefaultAction; | ||
|
|
|
Closing in favor of: #11888 |
A recreate of #11669 by recopying all flutter/flutter stuff from scratch, and cherry picking all of my subsequent commits. This is a single super mega PR attempting to migrate all Material and Cupertino code from flutter/flutter to material_ui and cupertino_ui. ### How the PR was created ``` git filter-repo --path packages/flutter/lib/src/material --path packages/flutter/test/material --path examples/api/lib/material --path examples/api/test/material --path packages/flutter/lib/src/cupertino --path packages/flutter/test/cupertino --path examples/api/lib/cupertino --path examples/api/test/cupertino --path packages/flutter/lib/fix_data/fix_material --path packages/flutter/test_fixes/material --path packages/flutter/lib/fix_data/fix_cupertino.yaml --path packages/flutter/test_fixes/cupertino cd ../packages git remote add source-origin ../flutter git fetch source-origin git merge source-origin/master --allow-unrelated-histories ``` I then cherry picked everything I could from the previous PR (#11669), skipping merge commits. ### What was included in the copy * The main source code (packages/flutter/lib/src/<material/cupertino>). * The widget/unit tests (packages/flutter/test/<material/cupertino>). * The examples (examples/api/lib/<material/cupertino>). * The example tests (examples/api/test/<material/cupertino>). * The dart fixes (packages/flutter/lib/fix_data). * The dart fix tests (packages/flutter/test_fixes). ### TODOs * [x] Do exports for Material and Cupertino. * [x] Confirm the directory structure (current plan: lib/src/ for now, reorganize after 1.0.0). * [x] Try installing and using the packages locally. * [x] Try running the tests locally (works except for tests with cross imports). * [x] Try running the example tests locally (work after migrating `package:flutter_api_samples` import). * [x] Verify examples work. * [x] Verify that `git blame` appears the same in both repos on various files. (Yes, but the SHAs are different, as expected.) * [x] Add auxiliary files for dart fixes and tests. * [x] Port imports of material/cupertino in places like examples/test to use the new packages. * [x] ~~Fix~~ Skip all test cross imports. * [x] Make sure the analyzer is working in the same exact way as it does in flutter/flutter. (#11692) ### Open questions * ~~Are we sure about the directory structure?~~ * Confirmed with @dkwingsmt and @QuncCccccc. * Anything else that should be ported along with this? If these commits touch files that are not included in this PR, but that we later port in, the commits will likely have different SHAs. * I'm hoping we got it all at this point but if anyone notices anything let me know. * ~~Do we like the examples setup?~~ * Worked with @stuartmorgan-g and @chunhtai to get this to match the other packages in this repo. * Are we cool with skipping cross imports tests and fixing them later? This approach should not fracture commits because the commits were made in flutter/flutter after the code was copied. * Tests are in the temporarily_skipped_tests folder. ### How to try using these packages Add the local packages to your project: ``` flutter pub add cupertino_ui --path ../../packages/packages/cupertino_ui flutter pub add material_ui --path ../../packages/packages/material_ui ``` Then import the packages instead of the libraries in the SDK: ```diff - import 'package:flutter/material.dart'; - import 'package:flutter/cupertino.dart'; + import 'package:material_ui/material_ui.dart'; + import 'package:cupertino_ui/cupertino_ui.dart'; ``` ### How to review this PR * Do read the PR description at the top, including Open Questions. * Don't read all 600k+ lines changed! Ignore the main source code and test files. The only thing I changed in there is to change imports from `flutter/material.dart` to `material_ui/material_ui.dart` and the equivalent for Cupertino. * Do look closely at the file tree browser on the left side of the "Files Changed" tab, though. Check the directory structure of material_ui and cupertino_ui and make sure it looks good to you. * Do take a look at the small config files like pubspecs, analysis_options, etc. * See the examples and their tests now located in material_ui/material_ui_examples and cupertino_ui/cupertino_ui_examples. * See the data driven fixes in lib/fix_data and their tests in test_fixes. And let me know if there is any code that's not in this PR that you expected to be. It will be best to get everything we can in this one PR rather than following up later in order to prevent fragmenting commits. ### Resources * Closed PR where i tried to import everything but forgot dart fixes. - #11568 * Closed PR where I tried and failed to import a single widget by individually importing all of its transitive dependencies with `git filter-repo` commands. * #11526 * Closed PR where I tried to import just colors.dart (no dependencies), but found that it would create different SHAs between it and this mega PR. * #11543 * Closed PR where I tried to import all of Material, before realizing that I would create different SHAs between that PR and a future Cupertino PR. * #11549 * Closed main big PR with most of the history: #11669 * Closed PR where I tried to cherry pick everything: #11887
A recreation of #11669 to get on the latest
mainand keep the history clean.Copies over flutter/flutter's Material/Cupertino code and related stuff, and sets it up in this repo.