Flutter Gallery Documentation

repository·main·Indexed 27 days ago

https://github.com/flutter-team-archive/gallery

A 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.

Tokens
7.7K
Snippets
27
Records
61
Agent score
92%

What's inside Flutter Gallery

  1. Generate highlighted code segments with Codeviewer CLI

    main

    Codeviewer 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 to lib/codeviewer/code_segments.dart.

    To generate code segments, run these commands from the gallery/ directory:

    1. Ensure grinder is installed: flutter pub get
    2. Run the update command: flutter pub run grinder update-code-segments
    flutter pub get
    flutter pub run grinder update-code-segments
  2. Define code blocks for highlighting

    main

    To mark a specific block of code for highlighting, wrap it with // BEGIN yourDemoName and // END comments.

    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) inside gallery/lib/codeviewer/code_segments.dart.

    To display the highlighted code in the gallery, you must register it in gallery/lib/data/demos.dart by adding the code property to your GalleryDemoConfiguration object:

    code: CodeSegments.yourDemoName,
    code: CodeSegments.yourDemoName,
  3. Add new localized strings via intl_en.arb

    main

    To add new strings to the application, use intl_en.arb as the template. Each new entry must follow a specific format consisting of a Dart getter variable name and a metadata object containing a description. The dartGetterVariableName will 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 the GalleryLocalizations delegate, even before other languages are translated.

      "dartGetterVariableName": "english translation of the message",
      "@dartGetterVariableName": {
        "description": "description that the localizations delegate will use."
      },
  4. Generate localizations

    main

    If 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 l10n
  5. Use multiple or nested code blocks

    main

    Codeviewer supports joining multiple blocks into a single segment or handling nested/overlapping blocks.

    Joining Blocks

    If you use multiple BEGIN and END markers 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();
    // END

    Results in:

    c();
    a();

    Nested and Overlapping Blocks

    Blocks can be nested or overlap. When nesting, ensure you specify which file/block to END correctly.

    Example of nesting:

    // BEGIN demoOne
    a();
    // BEGIN demoTwo
    b();
    // END demoOne
    c();
    // END demoTwo

    This produces two segments:

    • demoOne: a(); b();
    • demoTwo: b(); c();
  6. Update golden tests

    main

    When 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:

    1. Locate the failed GitHub Actions job.
    2. Download the goldens folder from the Artifacts section at the bottom of the Summary page.
    3. Use the downloaded images (which include the golden image, the test image, and the difference) within your branch.
    flutter test --update-goldens test_goldens