flutter/examples/api
Greg Spencer fd9ce27748
Clean up examples, remove section markers and --template args (#91133)
This does a cleanup of the examples, removing all of the "section" markers and extra comments that we don't need anymore now that the samples are no longer in the source code. It also removes the --template arguments from the {@tool dartpad} and {@tool sample} directives, since those are no longer used. It converts two examples that I discovered were still embedded into linked examples in the examples folder.

I didn't delete the templates from the snippets config folder yet, because there are still embedded samples in the dart:ui package from the engine that use them. Once dart:ui no longer uses the templates, they can be removed.

I bumped the version of the snippets package to pick up a change that allows removal of the --template argument.
2021-10-04 12:16:17 -07:00
..
android Add smoke tests for all the examples, fix 17 broken examples. (#89021) 2021-09-28 09:32:06 -07:00
ios Add smoke tests for all the examples, fix 17 broken examples. (#89021) 2021-09-28 09:32:06 -07:00
lib Clean up examples, remove section markers and --template args (#91133) 2021-10-04 12:16:17 -07:00
linux Add smoke tests for all the examples, fix 17 broken examples. (#89021) 2021-09-28 09:32:06 -07:00
macos Add smoke tests for all the examples, fix 17 broken examples. (#89021) 2021-09-28 09:32:06 -07:00
test_driver Add smoke tests for all the examples, fix 17 broken examples. (#89021) 2021-09-28 09:32:06 -07:00
web Add smoke tests for all the examples, fix 17 broken examples. (#89021) 2021-09-28 09:32:06 -07:00
windows Add smoke tests for all the examples, fix 17 broken examples. (#89021) 2021-09-28 09:32:06 -07:00
.metadata Extract Sample code into examples/api (#87280) 2021-08-25 09:45:12 -07:00
pubspec.yaml Clean up dependency pins and update all packages (#91109) 2021-10-04 10:28:03 -07:00
README.md Extract Sample code into examples/api (#87280) 2021-08-25 09:45:12 -07:00

API Example Code

This directory contains the API sample code that is referenced from the API documentation in each class.

They 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, to run, in Chrome, the first example from the Curve2D class, you would run it like so, from this api directory:

% flutter run -d chrome lib/animation/curves/curve2_d.0.dart

These same examples are available on the API docs site. For instance, the example above is available on this page. Most of them are available as interactive examples in Dartpad, but some just don't make sense on the web, and so are available as standalone examples that can be run here.

Naming

The naming scheme for the files is similar to the hierarchy under packages/flutter/lib/src, except that the files are represented as directories, and each sample in each file as a separate file in that directory. So, for the example above, the examples are from the packages/flutter/lib/src/animation/curves.dart file, the Curve2D class, and the first sample (hence the index "0") for that symbol resides in the lib/animation/curves/curve2_d.0.dart file.

Authoring

When authoring these examples, place a block like so 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 Curve2D class. First add the stub to the symbol documentation:

/// {@tool dartpad --template=material_scaffold}
/// Write a description of the example here. This description will appear in the
/// API web documentation to introduce the example.
///
/// ```dart
/// // These are the sections you want to fill out in the template.
/// // They will be transferred to the example file when you extract it.
/// ```
/// {@end-tool}

Then install the extract_sample command with:

% pub global activate snippets

And run the extract_sample command from the Flutter repo dir:

$ pub global run extract_sample packages/flutter/lib/src/animation/curves.dart

This will create a new file in the examples/api directory, in this case it would create examples/api/lib/animation/curves/curve2_d.1.dart