Flutter Gallery Documentation
repository·main·Indexed 27 days ago
https://github.com/flutter-team-archive/galleryA deprecated showcase application used for testing Flutter's capabilities and as a reference for building various UI styles. The documentation covers development tasks including localization via .arb files, generating highlighted code segments with the Codeviewer CLI, updating golden tests, and managing Android Fastlane actions and iOS launch screen assets.
What's inside Flutter Gallery
- Flutter Gallery is a deprecated resource that was originally designed to help developers evaluate and use the Flutter framework. It is currently used primarily for testing purposes and is no longer actively maintained.
Overview of Web Benchmark Tests
mainThelib/benchmarks/directory contains performance tests specifically for running the Flutter Gallery on the Web. These benchmarks are utilized by theweb_benchmarkstool within the main Flutter repository to track and collect performance metrics for the Gallery.Use the l10n CLI to convert .arb files to .xml
mainThel10ncommand-line application is used to convert.arb(Application Resource Bundle) files into.xmlfiles. This process is intended to prepare localization data for consumption by translation tools or systems that require XML format.Generate highlighted code segments with Codeviewer CLI
mainCodeviewer is a command-line tool used to highlight Dart source code before compilation to prevent delays during app runtime. It scans files in the
lib/demos/folder and writes the highlighted widgets tolib/codeviewer/code_segments.dart.To generate code segments, run these commands from the
gallery/directory:- Ensure
grinderis installed:flutter pub get - Run the update command:
flutter pub run grinder update-code-segments
flutter pub get flutter pub run grinder update-code-segments- Ensure
Define code blocks for highlighting
mainTo mark a specific block of code for highlighting, wrap it with
// BEGIN yourDemoNameand// ENDcomments.When processed, the highlighter automatically includes the code within the markers, as well as any copyright notices and imports at the start of the file. The result is stored as a static method:
static TextSpan yourDemoName(BuildContext context)insidegallery/lib/codeviewer/code_segments.dart.To display the highlighted code in the gallery, you must register it in
gallery/lib/data/demos.dartby adding thecodeproperty to yourGalleryDemoConfigurationobject:code: CodeSegments.yourDemoName,code: CodeSegments.yourDemoName,Add new localized strings via intl_en.arb
mainTo add new strings to the application, use
intl_en.arbas the template. Each new entry must follow a specific format consisting of a Dart getter variable name and a metadata object containing a description. ThedartGetterVariableNamewill be the name used to access the string in your Dart code via the localizations delegate.Once added to
intl_en.arb, you can use the English version immediately in your code after regenerating theGalleryLocalizationsdelegate, even before other languages are translated."dartGetterVariableName": "english translation of the message", "@dartGetterVariableName": { "description": "description that the localizations delegate will use." },Explore Material 3 features in Flutter
mainTo see how Material 3 features are implemented in the Flutter Material library, use the Material 3 Demo.
Run Web Benchmark Tests
mainTo run these performance tests, follow the instructions provided in the official Flutter repository's macrobenchmarks documentation. The Gallery benchmarks are integrated into the Flutter
web_benchmarksworkflow.Refer to the following external guide for detailed execution steps: https://github.com/flutter/flutter/tree/master/dev/benchmarks/macrobenchmarks#web-benchmarks
Generate localizations
mainIf this is the first time building the Flutter Gallery, localized code will not be present in the project directory. After running the application for the first time, a synthetic package is generated containing the app's localizations via
package:flutter_gen/gen_l10n/. To generate them manually, run the following commands:flutter pub get flutter pub run grinder l10nUse multiple or nested code blocks
mainCodeviewer supports joining multiple blocks into a single segment or handling nested/overlapping blocks.
Joining Blocks
If you use multiple
BEGINandENDmarkers with different suffixes (e.g.,#1,#2), the segments are joined in the order of their suffix number. For example:// BEGIN yourDemo#2 a(); // END b(); // BEGIN yourDemo#1 c(); // ENDResults in:
c(); a();Nested and Overlapping Blocks
Blocks can be nested or overlap. When nesting, ensure you specify which file/block to
ENDcorrectly.Example of nesting:
// BEGIN demoOne a(); // BEGIN demoTwo b(); // END demoOne c(); // END demoTwoThis produces two segments:
- demoOne:
a(); b(); - demoTwo:
b(); c();
- demoOne:
Access Flutter best practices and samples
mainThe Flutter Samples collection provides open source samples that illustrate best practices for Flutter development.
- Samples: https://flutter.github.io/samples
- Source Code: https://github.com/flutter/samples
Update golden tests
mainWhen an intentional UI change causes golden tests (screenshot tests) to fail, you must update the saved golden images.
Important: Due to rendering differences across platforms (especially regarding text), these tests are designed to run on macOS in GitHub Actions. If you update goldens on Linux or Windows, they will likely fail in the CI environment.
If you are not on macOS, the recommended workflow is:
- Locate the failed GitHub Actions job.
- Download the
goldensfolder from the Artifacts section at the bottom of the Summary page. - Use the downloaded images (which include the golden image, the test image, and the difference) within your branch.
flutter test --update-goldens test_goldens