Skip to content

[material_ui, cupertino_ui] Add unit tests for snippets #188530

Open

Description

@dkwingsmt

(This issue is linked by TODO comments in flutter/packages.)

There are many code snippets in the API doc that were once {@tool snippet} and were not covered by unit tests. We should add unit tests to avoid bit rot.

Solution 1: #region directives (recommended)

The Dart team has completed a new feature, the #region directive, where we can specify only a part of an example file to be imported by the API doc. dart-lang/dartdoc#4253

Solution 2: Code excerpts

Code excerpts are an existing mechanism in flutter/packages's CI workflow to guarantee two snippets across different files are identical. It is currently only applied to READMEs. This might need prerequisite work to expand its support to source files.

Expected format

Example:

// packages/material_ui/lib/src/circle_avatar.dart

/// <example>
///
/// If the avatar is to have an image, the image should be specified in the
/// [backgroundImage] property:
///
// @code-excerpt "../../tests/circle_avatar_test.dart (basic)"
/// ```dart
/// final avatar = CircleAvatar(
///   backgroundImage: NetworkImage(userAvatarUrl),
/// );
/// ```
///
/// </example>
// packages/material_ui/test/circle_avatar_test.dart

void main() {
  testWidgets('CircleAvatar basic example', (WidgetTester tester) async {
    // #docregion basic
    final avatar = CircleAvatar(
      backgroundImage: NetworkImage(userAvatarUrl),
    );
    // #enddocregion basic
     
    // Test the widget works as expected here...
  });
}

Activity

  1. added
    in triagePresently being triaged by the triage team
    a: tests"flutter test", flutter_test, or one of our tests
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    p: cupertino_uicupertino_ui package in flutter/packages
    team-designOwned by Design Languages team
    and removed
    in triagePresently being triaged by the triage team
    on Jun 25, 2026
  2. added
    P1High-priority issues at the top of the work list
    triaged-designTriaged by Design Languages team
    on Jul 1, 2026
  3. added
    packageflutter/packages repository. See also p: labels.
    and removed
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Aug 17, 2026
  4. dkwingsmt commented on Sep 25, 2026

    @dkwingsmt
    ContributorAuthor

    I've conducted an analysis throughout the flutter/packages repository. After excluding some non-significant items (which we'll come back to later), the list of TODO are listed below. The list is divided into batches of size 3~7 for the convenience of reviewers.

    Part 1: packages/cupertino_ui (25 items, Batches 1–5)

    Deferred: These items are on hold because these files will be deprecated soon.

    Batch 1: CupertinoApp (5 items)

    1. app.dart:72 — CupertinoApp class doc
    2. app.dart:96 — CupertinoApp class doc
    3. app.dart:129 — CupertinoApp class doc
    4. app.dart:377 — CupertinoApp.shortcuts
    5. app.dart:410 — CupertinoApp.actions

    Batch 2: CupertinoSwitch (5 items)

    1. switch.dart:95 — CupertinoSwitch class doc (CupertinoSwitch inside CupertinoListTile and MergeSemantics)
    2. switch.dart:323 — CupertinoSwitch.trackOutlineColor
    3. switch.dart:358 — CupertinoSwitch.trackOutlineWidth
    4. switch.dart:396 — CupertinoSwitch.thumbIcon
    5. switch.dart:432 — CupertinoSwitch.mouseCursor

    Batch 3: CupertinoDynamicColor & CupertinoContextMenu (5 items)

    1. colors.dart:666 — CupertinoDynamicColor class doc (custom widget resolving dynamic color)
    2. colors.dart:696 — CupertinoDynamicColor class doc (using CupertinoDynamicColor in CupertinoThemeData)
    3. colors.dart:727 — CupertinoDynamicColor class doc (resolving explicitly via CupertinoDynamicColor.resolve)
    4. context_menu.dart:161 — CupertinoContextMenu.kOpenBorderRadius
    5. context_menu.dart:271 — CupertinoContextMenu.builder

    Batch 4: Cupertino Pickers, Slider & Segmented Control (5 items)

    1. date_picker.dart:494 — CupertinoDatePicker.selectionOverlayBuilder
    2. date_picker.dart:2280 — CupertinoTimerPicker.selectionOverlayBuilder
    3. slider.dart:148 — CupertinoSlider.onChangeStart
    4. slider.dart:185 — CupertinoSlider.onChangeEnd
    5. sliding_segmented_control.dart:435 — CupertinoSlidingSegmentedControl.onValueChanged

    Batch 5: Cupertino Text Fields, Magnifier & Icons (5 items)

    1. magnifier.dart:19 — CupertinoTextMagnifier class doc
    2. magnifier.dart:231 — CupertinoMagnifier class doc
    3. text_field.dart:918 — CupertinoTextField.magnifierConfiguration
    4. text_form_field_row.dart:53 — CupertinoTextFormFieldRow class doc
    5. icons.dart:26 — CupertinoIcons class doc

    Part 2: packages/material_ui (130 items, Batches 6–23)

    Batch 6: MaterialApp (5 items)

    Done: flutter/packages#13021

    1. app.dart:123 — MaterialApp class doc (basic home Scaffold)
    2. app.dart:146 — MaterialApp class doc (routes map)
    3. app.dart:177 — MaterialApp class doc (theme configuration)
    4. app.dart:698 — MaterialApp.shortcuts
    5. app.dart:731 — MaterialApp.actions

    Batch 7: AppBar, SliverAppBar, BottomAppBar & Scaffold (5 items)

    Done: flutter/packages#13023

    1. app_bar.dart:291 — AppBar.leading
    2. app_bar.dart:392 — AppBar.actions
    3. app_bar.dart:1538 — SliverAppBar class doc
    4. bottom_app_bar.dart:32 — BottomAppBar class doc
    5. scaffold.dart:1704 — Scaffold class doc

    Batch 8: Switch (5 items)

    Done: flutter/packages#13052

    1. switch.dart:337 — Switch.thumbColor (material_ui.switch.thumbColor template)
    2. switch.dart:383 — Switch.trackColor (material_ui.switch.trackColor template)
    3. switch.dart:429 — Switch.trackOutlineColor (material_ui.switch.trackOutlineColor template)
    4. switch.dart:468 — Switch.trackOutlineWidth (material_ui.switch.trackOutlineWidth template)
    5. switch.dart:505 — Switch.thumbIcon (material_ui.switch.thumbIcon template)

    Batch 9: Checkbox, CheckboxListTile, Radio & RadioListTile (5 items)

    1. checkbox.dart:234 — Checkbox.fillColor (material_ui.checkbox.fillColor template)
    2. checkbox_list_tile.dart:66 — CheckboxListTile class doc
    3. checkbox_list_tile.dart:313 — CheckboxListTile.onChanged
    4. radio.dart:265 — Radio.fillColor (material_ui.radio.fillColor template)
    5. radio_list_tile.dart:68 — RadioListTile class doc

    Batch 10: ListTile & SwitchListTile (6 items)

    Done: flutter/packages#13097

    1. list_tile.dart:208 — ListTile class doc (Card + ListTile samples)
    2. list_tile.dart:306 — ListTile class doc (one-line ListTile)
    3. list_tile.dart:336 — ListTile class doc (two-line ListTile)
    4. list_tile.dart:369 — ListTile class doc (three-line ListTile)
    5. switch_list_tile.dart:71 — SwitchListTile class doc
    6. switch_list_tile.dart:341 — SwitchListTile.onChanged

    Batch 11: Chip & ChipTheme (5 items)

    1. chip.dart:479 — SelectableChipAttributes.onSelected
    2. chip.dart:614 — TappableChipAttributes.onPressed
    3. chip.dart:697 — Chip class doc
    4. chip_theme.dart:67 — ChipTheme.of
    5. chip_theme.dart:131 — ChipThemeData class doc

    Batch 12: Dialog, AlertDialog & SimpleDialog (5 items)

    1. dialog.dart:61 — Dialog class doc
    2. dialog.dart:342 — AlertDialog class doc
    3. dialog.dart:652 — AlertDialog.actionsPadding
    4. dialog.dart:1067 — SimpleDialogOption class doc
    5. dialog.dart:1139 — SimpleDialog class doc

    Batch 13: Slider & SliderTheme (6 items)

    1. slider.dart:307 — Slider.onChanged
    2. slider.dart:346 — Slider.onChangeStart
    3. slider.dart:383 — Slider.onChangeEnd
    4. slider.dart:550 — Slider.semanticFormatterCallback
    5. slider_theme.dart:71 — SliderTheme.of
    6. slider_theme.dart:259 — SliderThemeData constructor

    Batch 14: RangeSlider (4 items)

    1. range_slider.dart:209 — RangeSlider.onChanged
    2. range_slider.dart:245 — RangeSlider.onChangeStart
    3. range_slider.dart:284 — RangeSlider.onChangeEnd
    4. range_slider.dart:401 — RangeSlider.semanticFormatterCallback

    Batch 15: Menus (DropdownMenu, MenuAnchor & PopupMenu) (6 items)

    1. dropdown_menu.dart:597 — DropdownMenu.filterCallback
    2. dropdown_menu.dart:636 — DropdownMenu.searchCallback
    3. menu_anchor.dart:430 — MenuAnchor.onAnimationStatusChanged
    4. popup_menu.dart:153 — PopupMenuDivider.color
    5. popup_menu.dart:250 — PopupMenuItem class doc
    6. popup_menu.dart:507 — CheckedPopupMenuItem class doc

    Batch 16: Tab, TabController, DefaultTabController & DrawerController (6 items)

    1. tab_controller.dart:37 — TabController class doc
    2. tab_controller.dart:408 — DefaultTabController.maybeOf
    3. tab_controller.dart:440 — DefaultTabController.of
    4. tabs.dart:164 — Tab.height
    5. drawer.dart:433 — DrawerController.maybeOf
    6. drawer.dart:465 — DrawerController.of

    Batch 17: Text Input, Selection & Search (6 items)

    1. text_field.dart:812 — TextField.buildCounter
    2. text_form_field.dart:52 — TextFormField class doc
    3. selectable_text.dart:100 — SelectableText class doc (basic sample)
    4. selectable_text.dart:120 — SelectableText class doc (SelectableText.rich)
    5. text_selection_theme.dart:129 — TextSelectionTheme class doc
    6. search.dart:124 — SearchDelegate constructor

    Batch 18: TimeOfDay & showTimePicker (4 items)

    1. time.dart:35 — TimeOfDay class doc
    2. time_picker.dart:3145 — showTimePicker function doc (basic usage)
    3. time_picker.dart:3204 — showTimePicker function doc (RTL Directionality)
    4. time_picker.dart:3226 — showTimePicker function doc (alwaysUse24HourFormat)

    Batch 19: Divider, VerticalDivider, Ink & InkSparkle (6 items)

    1. divider.dart:139 — Divider.color (material_ui.Divider.color template)
    2. divider.dart:166 — Divider.createBorderSide
    3. divider.dart:331 — VerticalDivider.color
    4. ink_decoration.dart:52 — Ink class doc (Ink with InkWell)
    5. ink_decoration.dart:81 — Ink class doc (Ink.image)
    6. ink_sparkle.dart:48 — InkSparkle class doc

    Batch 20: CarouselView, CircleAvatar, SegmentedButton & Icons (7 items)

    1. carousel.dart:58 — CarouselView class doc
    2. carousel.dart:297 — CarouselView.weightedBuilder
    3. circle_avatar.dart:34 — CircleAvatar class doc (backgroundImage sample)
    4. circle_avatar.dart:52 — CircleAvatar class doc (initials Text sample)
    5. segmented_button.dart:263 — SegmentedButton.styleFrom
    6. icons.dart:130 — Icons class doc
    7. icons.dart:182 — Icons.adaptive

    Batch 21: ThemeData, TextTheme, ProgressIndicatorTheme & TooltipTheme (5 items)

    1. theme_data.dart:922 — ThemeData.from
    2. text_theme.dart:242 — TextTheme.copyWith
    3. text_theme.dart:334 — TextTheme.merge
    4. progress_indicator_theme.dart:321 — ProgressIndicatorTheme class doc
    5. tooltip_theme.dart:323 — TooltipTheme class doc

    Batch 22: MaterialState & ColorScheme (7 items)

    1. material_state.dart:112 — MaterialStateColor (deprecated typedef)
    2. material_state_mixin.dart:24 — MaterialStateMixin mixin doc
    3. material_state_mixin.dart:81 — MaterialStateMixin.updateMaterialState
    4. color_scheme.dart:446 — ColorScheme.light
    5. color_scheme.dart:541 — ColorScheme.dark
    6. color_scheme.dart:638 — ColorScheme.highContrastLight
    7. color_scheme.dart:734 — ColorScheme.highContrastDark

    Batch 23: Colors Class Doc & Swatches

    Deferred: These items are on hold pending team discussion because they're largely repetitive and trivial.

    1. colors.dart:192 — Colors class doc (Colors.green[400])
    2. colors.dart:206 — Colors class doc (Container(color: Colors.blue))
    3. colors.dart:531 — Colors.red
    4. colors.dart:576 — Colors.redAccent
    5. colors.dart:615 — Colors.pink
    6. colors.dart:660 — Colors.pinkAccent
    7. colors.dart:702 — Colors.purple
    8. colors.dart:747 — Colors.purpleAccent
    9. colors.dart:789 — Colors.deepPurple
    10. colors.dart:834 — Colors.deepPurpleAccent
    11. colors.dart:876 — Colors.indigo
    12. colors.dart:921 — Colors.indigoAccent
    13. colors.dart:965 — Colors.blue
    14. colors.dart:1010 — Colors.blueAccent
    15. colors.dart:1052 — Colors.lightBlue
    16. colors.dart:1097 — Colors.lightBlueAccent
    17. colors.dart:1141 — Colors.cyan
    18. colors.dart:1186 — Colors.cyanAccent
    19. colors.dart:1228 — Colors.teal
    20. colors.dart:1273 — Colors.tealAccent
    21. colors.dart:1318 — Colors.green
    22. colors.dart:1366 — Colors.greenAccent
    23. colors.dart:1408 — Colors.lightGreen
    24. colors.dart:1453 — Colors.lightGreenAccent
    25. colors.dart:1495 — Colors.lime
    26. colors.dart:1540 — Colors.limeAccent
    27. colors.dart:1582 — Colors.yellow
    28. colors.dart:1627 — Colors.yellowAccent
    29. colors.dart:1669 — Colors.amber
    30. colors.dart:1714 — Colors.amberAccent
    31. colors.dart:1758 — Colors.orange
    32. colors.dart:1803 — Colors.orangeAccent
    33. colors.dart:1847 — Colors.deepOrange
    34. colors.dart:1892 — Colors.deepOrangeAccent
    35. colors.dart:1933 — Colors.brown
    36. colors.dart:1981 — Colors.grey
    37. colors.dart:2030 — Colors.blueGrey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work lista: tests"flutter test", flutter_test, or one of our testsp: cupertino_uicupertino_ui package in flutter/packagesp: material_uimaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions