-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Decoupling Material and Cupertino (with dart fixes) #11669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 250 commits
04a9f87
68ec8f8
4379a84
381fd35
bae2117
9a79874
9684541
2fb7649
7d6b318
49eaa60
bf96b39
0933360
976e527
0a0bbeb
eea19db
0e8dc90
a49d689
827f370
3fce10d
f5a6611
d9cc959
e28c031
ff7cba2
7a0ecd5
fdfd26c
3533eb2
b6ada8e
f700832
f623bdd
2c370bd
ee94b62
64f0d16
489a271
4a861cc
6d0f81b
ad5d64f
de4c546
e62ed2e
4a0b28a
e25711e
668e27f
0ff87e0
543fee1
cca8f66
5ec82e1
fbe3345
b2fef10
9135736
181c04f
cca9439
5381c45
eebe9fe
01474d5
8fc8eba
52ce949
e072fae
c9c9e3a
c9403d6
18b9fd6
bdbf451
924bcc6
2726183
0f0617c
2fb97ec
ef5fd72
02b9689
d5a11db
be08c73
7a03609
afc5454
857d975
c2f77cc
e54437d
27db7c2
a0bc453
354799c
eb91373
8f5d7f7
8a42365
113e8c3
27f62de
52c42fd
e7d41b4
594acaa
4ae34e3
e10bf0d
2f8ed09
8e87f9e
10c829c
50422f2
fc7d610
03564c8
0db5499
337b5fc
7ab663a
e65a3b5
e3dbc76
70d9098
60bd72a
67956a0
59c76f1
e57ced2
ace6c25
765aa21
e6b568a
e9cfcbc
51a467c
f4d5a3e
c2638a4
414ee23
28e1057
505083f
38fc030
41231eb
2f13faa
32dfb01
7f3694b
d9f81b9
dfac5b4
94b3b57
fe8bb22
8f89b5a
9129cf7
8a17526
589f5ef
04442ae
4052385
c2ae163
bc215ec
e7ec904
502f278
3cc588a
55c3a17
30e4964
66c0316
b7cb26b
5418e29
88ee022
cbd2cf9
df77016
828b094
a86697f
d44b247
69c2000
7489a3f
8411ba1
c99b833
f59572d
9a7f259
86c08b5
a9bf208
2d5853d
e7f001e
fa60a17
3c65e1a
564f347
4e90d1f
26a232f
4202752
2d9c390
e8b21b2
ac8a5cc
41ab796
407a368
7df96ba
e91301f
83f6dd4
35dad2c
59c8873
0037e39
9d7145f
2d0896b
37daf9c
19ff4a1
0e2a6b9
b2dc66b
54e094b
a336f29
12d0ee8
5b31e29
a80ac40
a1b48e9
a5a643a
29d73d4
e2b8a72
7170f77
2247e76
6db5aaf
269018c
69dea74
2fc901a
50144ea
5d536e7
f53cc85
ee41c63
7a72eca
2582828
3ee11b9
3b94e02
dc0d989
923e6e0
d227d26
552d733
8b55350
d9e1b34
dcb3f86
0b83bd5
a1e97c9
9defdae
f8db4f4
7b9f28c
62f3d4d
5e0c259
a4fc11b
d5cd369
b748886
fb62d65
fb0d6ac
71a4891
26def7c
9f17a4e
826c5b9
0472114
f0e4e1f
f9a6f56
6d40c22
51c9445
9ca98b7
afa1400
69833c1
aacb751
2cd6f87
48aa027
b7779c3
3ee626f
5c7f674
21b800d
b422d5b
aafc23b
2d8719a
8a136f3
380d25b
da6193b
15dd3b5
fe90891
35ba9d7
79aecdd
eeefb93
1d32f6d
073956b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| include: ../../analysis_options.yaml | ||
|
|
||
| formatter: | ||
| page_width: 100 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Unused platform specific files | ||
| android/ | ||
| ios/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # This file tracks properties of this Flutter project. | ||
| # Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
| # | ||
| # This file should be version controlled and should not be manually edited. | ||
|
|
||
| version: | ||
| revision: "89172fc6152056af222e0afcf6e2d6ee4e9f6f8f" | ||
| channel: "master" | ||
|
|
||
| project_type: package |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| # cupertino_ui API Example Code | ||
| This directory contains the example code that is referenced in the documentation | ||
| in cupertino_ui's source code. | ||
|
|
||
| These examples were originally located [in | ||
| flutter/flutter](https://github.com/flutter/flutter/tree/master/examples/api) | ||
| before the Cupertino library was decoupled and moved into its current home in | ||
| flutter/packages. | ||
|
|
||
| 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 | ||
| `CupertinoActivityIndicator` class in Chrome, you would run it like so from the | ||
| [api](.) | ||
| directory: | ||
|
|
||
| ``` | ||
| % flutter run -d chrome lib/activity_indicator/cupertino_activity_indicator.0.dart | ||
| ``` | ||
|
|
||
| All of these same examples are available on the API docs site. | ||
|
|
||
| <!-- 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). | ||
| --> | ||
|
|
||
| <!-- TODO(justinmc): Uncomment when Dartpads work again. | ||
| 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/file/class_name.n.dart` | ||
| > | ||
| > `lib/file/class_name.member_name.n.dart` | ||
|
|
||
| The naming scheme corresponds to the files under [lib/src](../lib/src) where | ||
| each file is represented as a directory (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 | ||
| [lib/src/activity_indicator.dart](../lib/src/activity_indicator.dart) file, the | ||
| `CupertinoActivityIndicator` class, the first sample (hence the index "0") for | ||
| that symbol resides in the file named | ||
| [lib/activity_indicator/cupertino_activity_indicator.0.dart](lib/activity_indicator/cupertino_activity_indicator.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 `CupertinoActivityIndicator` 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 cupertino_ui_examples/lib/activity_indicator/cupertino_activity_indicator.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. | ||
|
|
||
| <!-- TODO(justinmc): Uncomment when Dartpad works again. | ||
| 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 | ||
| [`cupertino_ui_examples/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 [cupertino_ui_examples](./) 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 [`cupertino_ui_examples`](.) | ||
| 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, an | ||
| `CupertinoActivityIndicator` example that resides in | ||
| [`lib/activity_indicator/cupertino_activity_indicator.0.dart`]( ./lib/activity_indicator/cupertino_activity_indicator.0.dart) would | ||
| have its tests in a file named | ||
| [`test/activity_indicator/cupertino_activity_indicator.0_test.dart`]( | ||
| ./test/activity_indicator/cupertino_activity_indicator.0_test.dart) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll need to add the new packages to script/configs/custom_analysis.yaml so CI doesn't fail on these local files. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # This file is also used by dev/bots/analyze_snippet_code.dart to analyze code snippets (`{@tool snippet}` sections). | ||
|
|
||
| # The following line activates a set of recommended lints for Flutter apps, | ||
| # packages, and plugins designed to encourage good coding practices. | ||
| include: package:flutter_lints/flutter.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 |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||
| // Copyright 2014 The Flutter Authors. All rights reserved. | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the files will need to change the first line to (different year, no period or "All right reserved.") to match the license standardization of this repo.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| // Use of this source code is governed by a BSD-style license that can be | ||||||
| // found in the LICENSE file. | ||||||
|
|
||||||
| import 'package:cupertino_ui/cupertino_ui.dart'; | ||||||
|
|
||||||
| /// Flutter code sample for [CupertinoActivityIndicator]. | ||||||
|
|
||||||
| void main() => runApp(const CupertinoIndicatorApp()); | ||||||
|
|
||||||
| class CupertinoIndicatorApp extends StatelessWidget { | ||||||
| const CupertinoIndicatorApp({super.key}); | ||||||
|
|
||||||
| @override | ||||||
| Widget build(BuildContext context) { | ||||||
| return const CupertinoApp( | ||||||
| theme: CupertinoThemeData(brightness: .light), | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The syntax
Suggested change
|
||||||
| home: CupertinoIndicatorExample(), | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| class CupertinoIndicatorExample extends StatelessWidget { | ||||||
| const CupertinoIndicatorExample({super.key}); | ||||||
|
|
||||||
| @override | ||||||
| Widget build(BuildContext context) { | ||||||
| return const CupertinoPageScaffold( | ||||||
| navigationBar: CupertinoNavigationBar( | ||||||
| middle: Text('CupertinoActivityIndicator Sample'), | ||||||
| ), | ||||||
| child: Center( | ||||||
| child: Column( | ||||||
| mainAxisAlignment: .spaceEvenly, | ||||||
| children: <Widget>[ | ||||||
| Column( | ||||||
| mainAxisAlignment: .center, | ||||||
| children: <Widget>[ | ||||||
| // Cupertino activity indicator with default properties. | ||||||
| CupertinoActivityIndicator(), | ||||||
| SizedBox(height: 10), | ||||||
| Text('Default'), | ||||||
| ], | ||||||
| ), | ||||||
| Column( | ||||||
| mainAxisAlignment: .center, | ||||||
| children: <Widget>[ | ||||||
| // Cupertino activity indicator with custom radius and color. | ||||||
| CupertinoActivityIndicator( | ||||||
| radius: 20.0, | ||||||
| color: CupertinoColors.activeBlue, | ||||||
| ), | ||||||
| SizedBox(height: 10), | ||||||
| Text( | ||||||
| 'radius: 20.0\ncolor: CupertinoColors.activeBlue', | ||||||
| textAlign: .center, | ||||||
| ), | ||||||
| ], | ||||||
| ), | ||||||
| Column( | ||||||
| mainAxisAlignment: .center, | ||||||
| children: <Widget>[ | ||||||
| // Cupertino activity indicator with custom radius and disabled | ||||||
| // animation. | ||||||
| CupertinoActivityIndicator(radius: 20.0, animating: false), | ||||||
| SizedBox(height: 10), | ||||||
| Text('radius: 20.0\nanimating: false', textAlign: .center), | ||||||
| ], | ||||||
| ), | ||||||
| ], | ||||||
| ), | ||||||
| ), | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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:cupertino_ui/cupertino_ui.dart'; | ||
|
|
||
| /// Flutter code sample for [CupertinoLinearActivityIndicator]. | ||
|
|
||
| void main() => runApp(const CupertinoLinearActivityIndicatorApp()); | ||
|
|
||
| class CupertinoLinearActivityIndicatorApp extends StatelessWidget { | ||
| const CupertinoLinearActivityIndicatorApp({super.key}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return const CupertinoApp( | ||
| theme: CupertinoThemeData(brightness: .light), | ||
| home: CupertinoIndicatorExample(), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class CupertinoIndicatorExample extends StatelessWidget { | ||
| const CupertinoIndicatorExample({super.key}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return const CupertinoPageScaffold( | ||
| navigationBar: CupertinoNavigationBar( | ||
| middle: Text('CupertinoLinearActivityIndicator Sample'), | ||
| ), | ||
| child: Padding( | ||
| padding: .all(8.0), | ||
| child: Column( | ||
| mainAxisAlignment: .spaceEvenly, | ||
| children: <Widget>[ | ||
| Column( | ||
| mainAxisAlignment: .center, | ||
| children: <Widget>[ | ||
| CupertinoLinearActivityIndicator(progress: 0), | ||
| SizedBox(height: 10), | ||
| Text('Progress: 0'), | ||
| ], | ||
| ), | ||
| Column( | ||
| mainAxisAlignment: .center, | ||
| children: <Widget>[ | ||
| CupertinoLinearActivityIndicator(progress: 0.2), | ||
| SizedBox(height: 10), | ||
| Text('Progress: 0.2', textAlign: .center), | ||
| ], | ||
| ), | ||
| Column( | ||
| mainAxisAlignment: .center, | ||
| children: <Widget>[ | ||
| CupertinoLinearActivityIndicator(progress: 0.4, height: 10), | ||
| SizedBox(height: 10), | ||
| Text('Height: 10', textAlign: .center), | ||
| ], | ||
| ), | ||
| Column( | ||
| mainAxisAlignment: .center, | ||
| children: <Widget>[ | ||
| CupertinoLinearActivityIndicator( | ||
| progress: 0.6, | ||
| color: CupertinoColors.activeGreen, | ||
| ), | ||
| SizedBox(height: 10), | ||
| Text('Color: green', textAlign: .center), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the READMEs need language annotations on all the blocks to pass CI.
You'll probably also need to temporarily add the two new packages to https://github.com/flutter/packages/blob/main/script/configs/temp_exclude_excerpt.yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stuartmorgan-g I get a 404 for the file you linked to, could you double check it?