Skip to content

Commit 0346a5d

Browse files
[cupertino_ui,material_ui] Import from flutter/flutter (#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
2 parents f0a495f + 7ffe1f1 commit 0346a5d

1,187 files changed

Lines changed: 676832 additions & 13 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
include: ../../analysis_options.yaml
2+
3+
analyzer:
4+
exclude:
5+
- "test_fixes/**"
6+
# TODO(justinmc): Remove the following exclusion when cross-imports are
7+
# fixed. See https://github.com/flutter/flutter/issues/177028.
8+
- "temporarily_disabled_tests/**"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# TODO(stuartmorgan): Remove this; see https://github.com/flutter/flutter/issues/102679
2+
exempt_from_excerpts: true
3+
release:
4+
batch: false
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Unused platform specific files
2+
android/
3+
ios/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "89172fc6152056af222e0afcf6e2d6ee4e9f6f8f"
8+
channel: "master"
9+
10+
project_type: package
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# cupertino_ui API Example Code
2+
This directory contains the example code that is referenced in the documentation
3+
in cupertino_ui's source code.
4+
5+
These examples were originally located [in
6+
flutter/flutter](https://github.com/flutter/flutter/tree/master/examples/api)
7+
before the Cupertino library was decoupled and moved into its current home in
8+
flutter/packages.
9+
10+
The examples can be run individually by just specifying the path to the example
11+
on the command line (or in the run configuration of an IDE).
12+
13+
For example (no pun intended!), to run the first example from the
14+
`CupertinoActivityIndicator` class in Chrome, you would run it like so from the
15+
[example](.) directory:
16+
17+
```sh
18+
% flutter run -d chrome lib/activity_indicator/cupertino_activity_indicator.0.dart
19+
```
20+
21+
All of these same examples are available on the API docs site.
22+
23+
<!-- TODO(justinmc): Include a link to the docs page with the example above like this: For instance, the example above is available on [this page](https://api.flutter.dev/flutter/animation/Curve2D-class.html#animation.Curve2D.1).
24+
-->
25+
26+
## Naming
27+
28+
> `lib/file/class_name.n.dart`
29+
>
30+
> `lib/file/class_name.member_name.n.dart`
31+
32+
The naming scheme corresponds to the files under [lib/src](../lib/src) where
33+
each file is represented as a directory (without the `.dart` suffix), and each
34+
sample in the file is a separate file in that directory. So, for the example
35+
above, where the examples are from the
36+
[lib/src/activity_indicator.dart](../lib/src/activity_indicator.dart) file, the
37+
`CupertinoActivityIndicator` class, the first sample (hence the index "0") for
38+
that symbol resides in the file named
39+
[lib/activity_indicator/cupertino_activity_indicator.0.dart](lib/activity_indicator/cupertino_activity_indicator.0.dart).
40+
41+
Symbol names are converted from "CamelCase" to "snake_case". Dots are left
42+
between symbol names, so the first example for symbol
43+
`InputDecoration.prefixIconConstraints` would be converted to
44+
`input_decoration.prefix_icon_constraints.0.dart`.
45+
46+
If the same example is linked to from multiple symbols, the source will be in
47+
the canonical location for one of the symbols, and the link in the API docs
48+
block for the other symbols will point to the first symbol's example location.
49+
50+
## Authoring
51+
52+
When authoring examples, first place a block in the Dartdoc documentation for
53+
the symbol you would like to attach it to. Here's what it might look like if you
54+
wanted to add a new example to the `CupertinoActivityIndicator` class:
55+
56+
```dart
57+
/// {@example /example/lib/activity_indicator/cupertino_activity_indicator.0.dart}
58+
/// Write a description of the example here. This description will appear in the
59+
/// API web documentation to introduce the example.
60+
/// {@end-example}
61+
```
62+
63+
The path parameter is from the root of the package when beginning with `/`,
64+
otherwise it is relative to the current file.
65+
66+
Once that comment block is inserted in the source code, create a new file at the
67+
appropriate path under [`example/lib`](./lib). See all of the existing examples
68+
in that directory for different types of examples with some best practices
69+
applied.
70+
71+
The filename should match the location of the source file it is linked from, and
72+
is named for the symbol it is attached to, in lower_snake_case, with an index
73+
relating to their order within the doc comment. So, for the
74+
`CupertinoActivityIndicator` example above, since it's in a file called
75+
`activity_indicator.dart`, and it's the first example, it should have the name
76+
`example/lib/activity_indicator/cupertino_activity_indicator.0.dart`.
77+
78+
You should also add tests for your example code under [`example/test`](./test),
79+
that matches their location under [lib](./lib), ending in `_test.dart`. See the
80+
section on [writing tests](#writing-tests) for more information on what kinds of
81+
tests to write.
82+
83+
The entire example should be in a single file.
84+
85+
Only packages that can be loaded by Dartpad may be imported. If you use one that
86+
hasn't been used in an example before, you may have to add it to the
87+
[pubspec.yaml](pubspec.yaml) in the [example](./) directory.
88+
89+
## Writing Tests
90+
91+
Examples are required to have tests. There is already a "smoke test" that simply
92+
builds and runs all the API examples, just to make sure that they start up
93+
without crashing. Test coverage is required for examples, but should take care
94+
not to complicate the example strictly for the purpose of testing.
95+
96+
As an example, in regular framework code, you might include a parameter for a
97+
`Platform` object that can be overridden by a test to supply a dummy platform,
98+
but in the example. This would be unnecessarily complex for the example. In all
99+
other ways, these are just normal tests. You don't need to re-test the
100+
functionality of the widget being used in the example, but you should test the
101+
functionality and integrity of the example itself.
102+
103+
Tests go into a directory under [test](./test) that matches their location under
104+
[lib](./lib). They are named the same as the example they are testing, with
105+
`_test.dart` at the end, like other tests. For instance, an
106+
`CupertinoActivityIndicator` example that resides in
107+
[`lib/activity_indicator/cupertino_activity_indicator.0.dart`]( ./lib/activity_indicator/cupertino_activity_indicator.0.dart) would
108+
have its tests in a file named
109+
[`test/activity_indicator/cupertino_activity_indicator.0_test.dart`](
110+
./test/activity_indicator/cupertino_activity_indicator.0_test.dart)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is also used by dev/bots/analyze_snippet_code.dart to analyze code snippets (`{@tool snippet}` sections).
2+
3+
# The following line activates a set of recommended lints for Flutter apps,
4+
# packages, and plugins designed to encourage good coding practices.
5+
include: package:flutter_lints/flutter.yaml
6+
7+
linter:
8+
rules:
9+
# Samples want to print things pretty often.
10+
avoid_print: false
11+
# Samples are sometimes incomplete and don't show usage of everything.
12+
unreachable_from_main: false
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:cupertino_ui/cupertino_ui.dart';
6+
7+
/// Flutter code sample for [CupertinoActivityIndicator].
8+
9+
void main() => runApp(const CupertinoIndicatorApp());
10+
11+
class CupertinoIndicatorApp extends StatelessWidget {
12+
const CupertinoIndicatorApp({super.key});
13+
14+
@override
15+
Widget build(BuildContext context) {
16+
return const CupertinoApp(
17+
theme: CupertinoThemeData(brightness: .light),
18+
home: CupertinoIndicatorExample(),
19+
);
20+
}
21+
}
22+
23+
class CupertinoIndicatorExample extends StatelessWidget {
24+
const CupertinoIndicatorExample({super.key});
25+
26+
@override
27+
Widget build(BuildContext context) {
28+
return const CupertinoPageScaffold(
29+
navigationBar: CupertinoNavigationBar(
30+
middle: Text('CupertinoActivityIndicator Sample'),
31+
),
32+
child: Center(
33+
child: Column(
34+
mainAxisAlignment: .spaceEvenly,
35+
children: <Widget>[
36+
Column(
37+
mainAxisAlignment: .center,
38+
children: <Widget>[
39+
// Cupertino activity indicator with default properties.
40+
CupertinoActivityIndicator(),
41+
SizedBox(height: 10),
42+
Text('Default'),
43+
],
44+
),
45+
Column(
46+
mainAxisAlignment: .center,
47+
children: <Widget>[
48+
// Cupertino activity indicator with custom radius and color.
49+
CupertinoActivityIndicator(
50+
radius: 20.0,
51+
color: CupertinoColors.activeBlue,
52+
),
53+
SizedBox(height: 10),
54+
Text(
55+
'radius: 20.0\ncolor: CupertinoColors.activeBlue',
56+
textAlign: .center,
57+
),
58+
],
59+
),
60+
Column(
61+
mainAxisAlignment: .center,
62+
children: <Widget>[
63+
// Cupertino activity indicator with custom radius and disabled
64+
// animation.
65+
CupertinoActivityIndicator(radius: 20.0, animating: false),
66+
SizedBox(height: 10),
67+
Text('radius: 20.0\nanimating: false', textAlign: .center),
68+
],
69+
),
70+
],
71+
),
72+
),
73+
);
74+
}
75+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:cupertino_ui/cupertino_ui.dart';
6+
7+
/// Flutter code sample for [CupertinoLinearActivityIndicator].
8+
9+
void main() => runApp(const CupertinoLinearActivityIndicatorApp());
10+
11+
class CupertinoLinearActivityIndicatorApp extends StatelessWidget {
12+
const CupertinoLinearActivityIndicatorApp({super.key});
13+
14+
@override
15+
Widget build(BuildContext context) {
16+
return const CupertinoApp(
17+
theme: CupertinoThemeData(brightness: .light),
18+
home: CupertinoIndicatorExample(),
19+
);
20+
}
21+
}
22+
23+
class CupertinoIndicatorExample extends StatelessWidget {
24+
const CupertinoIndicatorExample({super.key});
25+
26+
@override
27+
Widget build(BuildContext context) {
28+
return const CupertinoPageScaffold(
29+
navigationBar: CupertinoNavigationBar(
30+
middle: Text('CupertinoLinearActivityIndicator Sample'),
31+
),
32+
child: Padding(
33+
padding: .all(8.0),
34+
child: Column(
35+
mainAxisAlignment: .spaceEvenly,
36+
children: <Widget>[
37+
Column(
38+
mainAxisAlignment: .center,
39+
children: <Widget>[
40+
CupertinoLinearActivityIndicator(progress: 0),
41+
SizedBox(height: 10),
42+
Text('Progress: 0'),
43+
],
44+
),
45+
Column(
46+
mainAxisAlignment: .center,
47+
children: <Widget>[
48+
CupertinoLinearActivityIndicator(progress: 0.2),
49+
SizedBox(height: 10),
50+
Text('Progress: 0.2', textAlign: .center),
51+
],
52+
),
53+
Column(
54+
mainAxisAlignment: .center,
55+
children: <Widget>[
56+
CupertinoLinearActivityIndicator(progress: 0.4, height: 10),
57+
SizedBox(height: 10),
58+
Text('Height: 10', textAlign: .center),
59+
],
60+
),
61+
Column(
62+
mainAxisAlignment: .center,
63+
children: <Widget>[
64+
CupertinoLinearActivityIndicator(
65+
progress: 0.6,
66+
color: CupertinoColors.activeGreen,
67+
),
68+
SizedBox(height: 10),
69+
Text('Color: green', textAlign: .center),
70+
],
71+
),
72+
],
73+
),
74+
),
75+
);
76+
}
77+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:cupertino_ui/cupertino_ui.dart';
6+
7+
/// Flutter code sample for [CupertinoTabBar].
8+
9+
void main() => runApp(const CupertinoTabBarApp());
10+
11+
class CupertinoTabBarApp extends StatelessWidget {
12+
const CupertinoTabBarApp({super.key});
13+
14+
@override
15+
Widget build(BuildContext context) {
16+
return const CupertinoApp(
17+
theme: CupertinoThemeData(brightness: .light),
18+
home: CupertinoTabBarExample(),
19+
);
20+
}
21+
}
22+
23+
class CupertinoTabBarExample extends StatelessWidget {
24+
const CupertinoTabBarExample({super.key});
25+
26+
@override
27+
Widget build(BuildContext context) {
28+
return CupertinoTabScaffold(
29+
tabBar: CupertinoTabBar(
30+
items: const <BottomNavigationBarItem>[
31+
BottomNavigationBarItem(
32+
icon: Icon(CupertinoIcons.star_fill),
33+
label: 'Favorites',
34+
),
35+
BottomNavigationBarItem(
36+
icon: Icon(CupertinoIcons.clock_solid),
37+
label: 'Recents',
38+
),
39+
BottomNavigationBarItem(
40+
icon: Icon(CupertinoIcons.person_alt_circle_fill),
41+
label: 'Contacts',
42+
),
43+
BottomNavigationBarItem(
44+
icon: Icon(CupertinoIcons.circle_grid_3x3_fill),
45+
label: 'Keypad',
46+
),
47+
],
48+
),
49+
tabBuilder: (BuildContext context, int index) {
50+
return CupertinoTabView(
51+
builder: (BuildContext context) {
52+
return Center(child: Text('Content of tab $index'));
53+
},
54+
);
55+
},
56+
);
57+
}
58+
}

0 commit comments

Comments
 (0)