Skip to main content

waft_material/
checkbox_list_tile.rs

1//! Flutter counterpart: material_ui's `checkbox_list_tile.dart`.
2
3use std::fmt::{self, Debug};
4use std::rc::Rc;
5
6use waft_embedder::Color;
7use waft_foundation::{App, Ref, ValueChanged};
8use waft_gestures::GestureTapCallback;
9use waft_painting::{AnyBorderSide, EdgeInsetsGeometry, OutlinedBorderRef, ShapeBorderRef};
10use waft_services::MouseCursorRef;
11use waft_widgets::{
12    BuildContext, ExcludeFocus, FocusNodeRef, IntoWidget, KeyRef, MergeSemantics, StatelessWidget,
13    Transform, WidgetRef, WidgetState, WidgetStatePropertyRef, WidgetStates,
14    WidgetStatesController,
15};
16
17use crate::checkbox::Checkbox;
18use crate::checkbox_theme::CheckboxTheme;
19use crate::list_tile::{ListTile, ListTileControlAffinity, ListTileTitleAlignment};
20use crate::list_tile_theme::ListTileTheme;
21use crate::theme::Theme;
22use crate::theme_data::{MaterialTapTargetSize, VisualDensity};
23
24/// Dart's `_CheckboxType`.
25#[derive(Clone, Copy, Debug)]
26enum CheckboxType {
27    Material,
28    Adaptive,
29}
30
31/// A [`ListTile`] with a [`Checkbox`]. In other words, a checkbox with a label.
32///
33/// The entire list tile is interactive: tapping anywhere in the tile toggles
34/// the checkbox.
35///
36/// The [`value`](Self::value), [`on_changed`](Self::on_changed),
37/// [`active_color`](Self::active_color) and [`check_color`](Self::check_color) properties of
38/// this widget are identical to the similarly-named properties on the [`Checkbox`] widget.
39///
40/// The [`title`](Self::title), [`subtitle`](Self::subtitle),
41/// [`is_three_line`](Self::is_three_line), [`dense`](Self::dense), and
42/// [`content_padding`](Self::content_padding) properties are like those of the same name on
43/// [`ListTile`].
44///
45/// The [`selected`](Self::selected) property on this widget is similar to the
46/// [`ListTile::selected`] property. This tile's [`active_color`](Self::active_color) is used
47/// for the selected item's text color, or the theme's `CheckboxThemeData::overlay_color` if
48/// [`active_color`](Self::active_color) is null.
49///
50/// This widget does not coordinate the [`selected`](Self::selected) state and the
51/// [`value`](Self::value) state; to have the list tile appear selected when the checkbox is
52/// checked, pass the same value to both.
53///
54/// The checkbox is shown on the right by default in left-to-right languages
55/// (i.e. the trailing edge). This can be changed using
56/// [`control_affinity`](Self::control_affinity). The [`secondary`](Self::secondary) widget is
57/// placed on the opposite side. This maps to the [`ListTile::leading`] and
58/// [`ListTile::trailing`] properties of [`ListTile`].
59///
60/// This widget requires a `Material` widget ancestor in the tree to paint
61/// itself on, which is typically provided by the app's `Scaffold`.
62/// The [`tile_color`](Self::tile_color), and [`selected_tile_color`](Self::selected_tile_color)
63/// are not painted by the [`CheckboxListTile`] itself but by the `Material` widget ancestor.
64/// In this case, one can wrap a `Material` widget around the [`CheckboxListTile`].
65///
66/// ## Performance considerations when wrapping [`CheckboxListTile`] with `Material`
67///
68/// Wrapping a large number of [`CheckboxListTile`]s individually with `Material`s
69/// is expensive. Consider only wrapping the [`CheckboxListTile`]s that require it
70/// or include a common `Material` ancestor where possible.
71///
72/// To show the [`CheckboxListTile`] as disabled, pass null as the
73/// [`on_changed`](Self::on_changed) callback.
74///
75/// ## CheckboxListTile isn't exactly what I want
76///
77/// If the way CheckboxListTile pads and positions its elements isn't quite
78/// what you're looking for, you can create custom labeled checkbox widgets by
79/// combining [`Checkbox`] with other widgets, such as `Text`, `Padding` and
80/// `InkWell`.
81///
82/// See also:
83///
84///  * [`ListTileTheme`], which can be used to affect the style of list tiles,
85///    including checkbox list tiles.
86///  * `RadioListTile`, a similar widget for radio buttons.
87///  * `SwitchListTile`, a similar widget for switches.
88///  * [`ListTile`] and [`Checkbox`], the widgets from which this widget is made.
89pub struct CheckboxListTile {
90    pub key: Option<KeyRef>,
91    /// Whether this checkbox is checked.
92    pub value: Option<bool>,
93    /// Called when the value of the checkbox should change.
94    ///
95    /// The checkbox passes the new value to the callback but does not actually
96    /// change state until the parent widget rebuilds the checkbox tile with the
97    /// new value.
98    ///
99    /// If null, the checkbox will be displayed as disabled.
100    pub on_changed: Option<ValueChanged<Option<bool>>>,
101    /// The cursor for a mouse pointer when it enters or is hovering over the
102    /// widget.
103    ///
104    /// If [`mouse_cursor`](Self::mouse_cursor) is a `WidgetStateMouseCursor`,
105    /// `WidgetStateProperty::resolve` is used for the following [`WidgetState`]s:
106    ///
107    ///  * [`WidgetState::Selected`].
108    ///  * [`WidgetState::Hovered`].
109    ///  * [`WidgetState::Disabled`].
110    ///
111    /// If null, then the value of `CheckboxThemeData::mouse_cursor` is used. If
112    /// that is also null, then `WidgetStateMouseCursor::clickable` is used.
113    pub mouse_cursor: Option<MouseCursorRef>,
114    /// The color to use when this checkbox is checked.
115    ///
116    /// Defaults to `ColorScheme::secondary` of the current [`Theme`].
117    pub active_color: Option<Color>,
118    /// The color that fills the checkbox.
119    ///
120    /// Resolves in the following states:
121    ///  * [`WidgetState::Selected`].
122    ///  * [`WidgetState::Hovered`].
123    ///  * [`WidgetState::Disabled`].
124    ///
125    /// If null, then the value of [`active_color`](Self::active_color) is used in the selected
126    /// state. If that is also null, the value of `CheckboxThemeData::fill_color`
127    /// is used. If that is also null, then the default value is used.
128    pub fill_color: Option<WidgetStatePropertyRef<Option<Color>>>,
129    /// The color to use for the check icon when this checkbox is checked.
130    ///
131    /// Defaults to Color(0xFFFFFFFF).
132    pub check_color: Option<Color>,
133    /// The color for the checkbox's `Material` when a pointer is hovering over it.
134    pub hover_color: Option<Color>,
135    /// The color for the checkbox's `Material`.
136    ///
137    /// Resolves in the following states:
138    ///  * [`WidgetState::Pressed`].
139    ///  * [`WidgetState::Selected`].
140    ///  * [`WidgetState::Hovered`].
141    ///
142    /// If null, then the value of [`active_color`](Self::active_color) with alpha
143    /// `K_RADIAL_REACTION_ALPHA` and [`hover_color`](Self::hover_color) is used in the pressed
144    /// and hovered state. If that is also null, the value of
145    /// `CheckboxThemeData::overlay_color` is used. If that is also null, then the default
146    /// value is used in the pressed and hovered state.
147    pub overlay_color: Option<WidgetStatePropertyRef<Option<Color>>>,
148    /// The splash radius of the circular `Material` ink response.
149    ///
150    /// If null, then the value of `CheckboxThemeData::splash_radius` is used. If
151    /// that is also null, then `K_RADIAL_REACTION_RADIUS` is used.
152    pub splash_radius: Option<f64>,
153    /// Configures the minimum size of the tap target.
154    ///
155    /// Defaults to [`MaterialTapTargetSize::ShrinkWrap`].
156    pub material_tap_target_size: Option<MaterialTapTargetSize>,
157    /// Defines how compact the list tile's layout will be.
158    pub visual_density: Option<VisualDensity>,
159    /// An optional focus node to use as the focus node for this widget.
160    pub focus_node: Option<FocusNodeRef>,
161    /// Controls the interactive states of the backing [`ListTile`].
162    pub states_controller: Option<Ref<WidgetStatesController>>,
163    /// True if this widget will be selected as the initial focus when no other
164    /// node in its scope is currently focused.
165    pub autofocus: bool,
166    /// Defines the tile's `InkWell::custom_border` and `Ink::decoration` shape.
167    pub shape: Option<ShapeBorderRef>,
168    /// The color and width of the checkbox's border.
169    ///
170    /// The given value is passed directly to [`Checkbox::side`].
171    ///
172    /// If this property is null, then `CheckboxThemeData::side` of
173    /// `ThemeData::checkbox_theme` is used. If that is also null, then the side
174    /// will be width 2.
175    pub side: Option<AnyBorderSide>,
176    /// True if this checkbox wants to show an error state.
177    ///
178    /// Defaults to false.
179    pub is_error: bool,
180    /// Defines the background color of `ListTile` when [`selected`](Self::selected) is false.
181    pub tile_color: Option<Color>,
182    /// The primary content of the list tile.
183    ///
184    /// Typically a `Text` widget.
185    pub title: Option<WidgetRef>,
186    /// Additional content displayed below the title.
187    ///
188    /// Typically a `Text` widget.
189    pub subtitle: Option<WidgetRef>,
190    /// A widget to display on the opposite side of the tile from the checkbox.
191    ///
192    /// Typically an `Icon` widget.
193    pub secondary: Option<WidgetRef>,
194    /// Whether this list tile is intended to display three lines of text.
195    ///
196    /// If null then the ambient `ListTileThemeData::is_three_line` is used.
197    /// If that is also null, the default value is `false`.
198    pub is_three_line: Option<bool>,
199    /// Whether this list tile is part of a vertically dense list.
200    ///
201    /// If this property is null then its value is based on `ListTileThemeData::dense`.
202    pub dense: Option<bool>,
203    /// Whether to render icons and text in the [`active_color`](Self::active_color).
204    ///
205    /// No effort is made to automatically coordinate the [`selected`](Self::selected) state
206    /// and the [`value`](Self::value) state. To have the list tile appear selected when the
207    /// checkbox is checked, pass the same value to both.
208    ///
209    /// Normally, this property is left to its default value, false.
210    pub selected: bool,
211    /// Where to place the control relative to the text.
212    pub control_affinity: Option<ListTileControlAffinity>,
213    /// Defines insets surrounding the tile's contents.
214    ///
215    /// This value will surround the [`Checkbox`], [`title`](Self::title),
216    /// [`subtitle`](Self::subtitle), and [`secondary`](Self::secondary) widgets in
217    /// [`CheckboxListTile`].
218    ///
219    /// When the value is null, the [`content_padding`](Self::content_padding) is
220    /// `EdgeInsets.symmetric(horizontal: 16.0)`.
221    pub content_padding: Option<EdgeInsetsGeometry>,
222    /// If true the checkbox's [`value`](Self::value) can be true, false, or null.
223    ///
224    /// Checkbox displays a dash when its value is null.
225    ///
226    /// When a tri-state checkbox ([`tristate`](Self::tristate) is true) is tapped, its
227    /// [`on_changed`](Self::on_changed) callback will be applied to true if the current value
228    /// is false, to null if value is true, and to false if value is null (i.e. it cycles
229    /// through false => true => null => false when tapped).
230    ///
231    /// If tristate is false (the default), [`value`](Self::value) must not be null.
232    pub tristate: bool,
233    /// The shape of the checkbox's `Material`.
234    ///
235    /// If this property is null then `CheckboxThemeData::shape` of `ThemeData::checkbox_theme`
236    /// is used. If that's null then the shape will be a `RoundedRectangleBorder`
237    /// with a circular corner radius of 1.0.
238    pub checkbox_shape: Option<OutlinedBorderRef>,
239    /// If non-null, defines the background color when [`CheckboxListTile::selected`] is true.
240    pub selected_tile_color: Option<Color>,
241    /// Handler called when the focus changes.
242    ///
243    /// Called with true if this widget's node gains focus, and false if it loses
244    /// focus.
245    pub on_focus_change: Option<ValueChanged<bool>>,
246    /// Whether detected gestures should provide acoustic and/or haptic feedback.
247    ///
248    /// See also:
249    ///
250    ///  * `Feedback` for providing platform-specific feedback to certain actions.
251    pub enable_feedback: Option<bool>,
252    /// The horizontal gap between the titles and the leading/trailing widgets.
253    pub horizontal_title_gap: Option<f64>,
254    /// The minimum padding on the top and bottom of the title and subtitle widgets.
255    pub min_vertical_padding: Option<f64>,
256    /// The minimum width allocated for the `ListTile::leading` widget.
257    pub min_leading_width: Option<f64>,
258    /// The minimum height allocated for the `ListTile` widget.
259    pub min_tile_height: Option<f64>,
260    /// Whether the CheckboxListTile is interactive.
261    ///
262    /// If false, this list tile is styled with the disabled color from the
263    /// current [`Theme`] and the [`ListTile::on_tap`] callback is
264    /// inoperative.
265    pub enabled: Option<bool>,
266    /// Defines how [`ListTile::leading`] and [`ListTile::trailing`] are
267    /// vertically aligned relative to the [`ListTile`]'s titles
268    /// ([`ListTile::title`] and [`ListTile::subtitle`]).
269    ///
270    /// If this property is null then `ListTileThemeData::title_alignment`
271    /// is used. If that is also null then [`ListTileTitleAlignment::ThreeLine`]
272    /// is used.
273    ///
274    /// See also:
275    ///
276    /// * [`ListTileTheme::of`], which returns the nearest [`ListTileTheme`]'s
277    ///   `ListTileThemeData`.
278    pub title_alignment: Option<ListTileTitleAlignment>,
279    /// Whether to add button:true to the semantics if onTap is provided.
280    /// This is a temporary flag to help changing the behavior of ListTile onTap semantics.
281    pub internal_add_semantic_for_on_tap: bool,
282    /// Controls the scaling factor applied to the [`Checkbox`] within the [`CheckboxListTile`].
283    ///
284    /// Defaults to 1.0.
285    pub checkbox_scale_factor: f64,
286    /// The semantic label for the checkbox that will be announced by screen readers.
287    ///
288    /// This is announced by assistive technologies (e.g TalkBack/VoiceOver).
289    ///
290    /// This label does not show in the UI.
291    pub checkbox_semantic_label: Option<String>,
292    checkbox_type: CheckboxType,
293}
294
295/// The setters of `CheckboxListTile`'s optional arguments that hold a value.
296macro_rules! checkbox_list_tile_setters {
297    ($($field:ident: $ty:ty => $name:literal),* $(,)?) => {
298        $(
299            #[doc = concat!("Dart `CheckboxListTile(", $name, ":)`.")]
300            pub fn $field(mut self, $field: impl Into<$ty>) -> CheckboxListTile {
301                self.$field = Some($field.into());
302                self
303            }
304        )*
305    };
306}
307
308/// The setters of `CheckboxListTile`'s optional arguments that are widgets.
309macro_rules! checkbox_list_tile_widget_setters {
310    ($($field:ident => $name:literal),* $(,)?) => {
311        $(
312            #[doc = concat!("Dart `CheckboxListTile(", $name, ":)`.")]
313            pub fn $field<K>(mut self, $field: impl IntoWidget<K>) -> CheckboxListTile {
314                self.$field = Some($field.into_widget());
315                self
316            }
317        )*
318    };
319}
320
321impl CheckboxListTile {
322    /// Creates a combination of a list tile and a checkbox.
323    ///
324    /// The checkbox tile itself does not maintain any state. Instead, when the
325    /// state of the checkbox changes, the widget calls the [`on_changed`](Self::on_changed)
326    /// callback. Most widgets that use a checkbox will listen for the
327    /// [`on_changed`](Self::on_changed) callback and rebuild the checkbox tile with a new
328    /// [`value`](Self::value) to update the visual appearance of the checkbox.
329    ///
330    /// The following arguments are required:
331    ///
332    /// * `value`, which determines whether the checkbox is checked. The `value`
333    ///   can only be null if [`tristate`](Self::tristate) is true.
334    /// * `on_changed`, which is called when the value of the checkbox should
335    ///   change. It can be set to null to disable the checkbox.
336    pub fn new(
337        value: Option<bool>,
338        on_changed: Option<ValueChanged<Option<bool>>>,
339    ) -> CheckboxListTile {
340        CheckboxListTile::with_type(value, on_changed, CheckboxType::Material)
341    }
342
343    /// Creates a combination of a list tile and a platform adaptive checkbox.
344    ///
345    /// The checkbox uses [`Checkbox::adaptive`] to show a `CupertinoCheckbox` for
346    /// iOS platforms, or [`Checkbox`] for all others.
347    ///
348    /// All other properties are the same as [`CheckboxListTile`].
349    pub fn adaptive(
350        value: Option<bool>,
351        on_changed: Option<ValueChanged<Option<bool>>>,
352    ) -> CheckboxListTile {
353        CheckboxListTile::with_type(value, on_changed, CheckboxType::Adaptive)
354    }
355
356    fn with_type(
357        value: Option<bool>,
358        on_changed: Option<ValueChanged<Option<bool>>>,
359        checkbox_type: CheckboxType,
360    ) -> CheckboxListTile {
361        CheckboxListTile {
362            key: None,
363            value,
364            on_changed,
365            mouse_cursor: None,
366            active_color: None,
367            fill_color: None,
368            check_color: None,
369            hover_color: None,
370            overlay_color: None,
371            splash_radius: None,
372            material_tap_target_size: None,
373            visual_density: None,
374            focus_node: None,
375            states_controller: None,
376            autofocus: false,
377            shape: None,
378            side: None,
379            is_error: false,
380            tile_color: None,
381            title: None,
382            subtitle: None,
383            secondary: None,
384            is_three_line: None,
385            dense: None,
386            selected: false,
387            control_affinity: None,
388            content_padding: None,
389            tristate: false,
390            checkbox_shape: None,
391            selected_tile_color: None,
392            on_focus_change: None,
393            enable_feedback: None,
394            horizontal_title_gap: None,
395            min_vertical_padding: None,
396            min_leading_width: None,
397            min_tile_height: None,
398            enabled: None,
399            title_alignment: None,
400            internal_add_semantic_for_on_tap: false,
401            checkbox_scale_factor: 1.0,
402            checkbox_semantic_label: None,
403            checkbox_type,
404        }
405    }
406
407    /// Dart `CheckboxListTile(key:)`.
408    pub fn key(mut self, key: KeyRef) -> CheckboxListTile {
409        self.key = Some(key);
410        self
411    }
412
413    checkbox_list_tile_setters!(
414        mouse_cursor: MouseCursorRef => "mouseCursor",
415        active_color: Color => "activeColor",
416        fill_color: WidgetStatePropertyRef<Option<Color>> => "fillColor",
417        check_color: Color => "checkColor",
418        hover_color: Color => "hoverColor",
419        overlay_color: WidgetStatePropertyRef<Option<Color>> => "overlayColor",
420        splash_radius: f64 => "splashRadius",
421        material_tap_target_size: MaterialTapTargetSize => "materialTapTargetSize",
422        visual_density: VisualDensity => "visualDensity",
423        focus_node: FocusNodeRef => "focusNode",
424        states_controller: Ref<WidgetStatesController> => "statesController",
425        shape: ShapeBorderRef => "shape",
426        side: AnyBorderSide => "side",
427        tile_color: Color => "tileColor",
428        is_three_line: bool => "isThreeLine",
429        dense: bool => "dense",
430        control_affinity: ListTileControlAffinity => "controlAffinity",
431        content_padding: EdgeInsetsGeometry => "contentPadding",
432        checkbox_shape: OutlinedBorderRef => "checkboxShape",
433        selected_tile_color: Color => "selectedTileColor",
434        on_focus_change: ValueChanged<bool> => "onFocusChange",
435        enable_feedback: bool => "enableFeedback",
436        horizontal_title_gap: f64 => "horizontalTitleGap",
437        min_vertical_padding: f64 => "minVerticalPadding",
438        min_leading_width: f64 => "minLeadingWidth",
439        min_tile_height: f64 => "minTileHeight",
440        enabled: bool => "enabled",
441        title_alignment: ListTileTitleAlignment => "titleAlignment",
442        checkbox_semantic_label: String => "checkboxSemanticLabel",
443    );
444
445    checkbox_list_tile_widget_setters!(
446        title => "title",
447        subtitle => "subtitle",
448        secondary => "secondary",
449    );
450
451    /// Dart `CheckboxListTile(autofocus:)`.
452    pub fn autofocus(mut self, autofocus: bool) -> CheckboxListTile {
453        self.autofocus = autofocus;
454        self
455    }
456
457    /// Dart `CheckboxListTile(isError:)`.
458    pub fn is_error(mut self, is_error: bool) -> CheckboxListTile {
459        self.is_error = is_error;
460        self
461    }
462
463    /// Dart `CheckboxListTile(selected:)`.
464    pub fn selected(mut self, selected: bool) -> CheckboxListTile {
465        self.selected = selected;
466        self
467    }
468
469    /// Dart `CheckboxListTile(tristate:)`.
470    pub fn tristate(mut self, tristate: bool) -> CheckboxListTile {
471        self.tristate = tristate;
472        self
473    }
474
475    /// Dart `CheckboxListTile(internalAddSemanticForOnTap:)`.
476    pub fn internal_add_semantic_for_on_tap(
477        mut self,
478        internal_add_semantic_for_on_tap: bool,
479    ) -> CheckboxListTile {
480        self.internal_add_semantic_for_on_tap = internal_add_semantic_for_on_tap;
481        self
482    }
483
484    /// Dart `CheckboxListTile(checkboxScaleFactor:)`.
485    pub fn checkbox_scale_factor(mut self, checkbox_scale_factor: f64) -> CheckboxListTile {
486        self.checkbox_scale_factor = checkbox_scale_factor;
487        self
488    }
489
490    /// Dart's `_handleValueChange`, as the tap callback that reads this tile's value.
491    fn handle_value_change(&self) -> GestureTapCallback {
492        debug_assert!(self.on_changed.is_some());
493        let on_changed = Rc::clone(self.on_changed.as_ref().expect("an enabled tile"));
494        let value = self.value;
495        let tristate = self.tristate;
496        GestureTapCallback::new(move |app: &mut App| match value {
497            Some(false) => on_changed(app, Some(true)),
498            Some(true) => on_changed(app, if tristate { None } else { Some(false) }),
499            None => on_changed(app, Some(false)),
500        })
501    }
502
503    /// The `Checkbox` or `Checkbox.adaptive` Dart's `build` puts in the control slot.
504    fn build_checkbox(&self) -> Checkbox {
505        let on_changed = if self.enabled.unwrap_or(true) {
506            self.on_changed.clone()
507        } else {
508            None
509        };
510        let mut checkbox = match self.checkbox_type {
511            CheckboxType::Material => Checkbox::new(self.value, on_changed),
512            CheckboxType::Adaptive => Checkbox::adaptive(self.value, on_changed),
513        }
514        .material_tap_target_size(
515            self.material_tap_target_size
516                .unwrap_or(MaterialTapTargetSize::ShrinkWrap),
517        )
518        .autofocus(self.autofocus)
519        .tristate(self.tristate)
520        .is_error(self.is_error);
521        checkbox.mouse_cursor = self.mouse_cursor.clone();
522        checkbox.active_color = self.active_color;
523        checkbox.fill_color = self.fill_color.clone();
524        checkbox.check_color = self.check_color;
525        checkbox.hover_color = self.hover_color;
526        checkbox.overlay_color = self.overlay_color.clone();
527        checkbox.splash_radius = self.splash_radius;
528        checkbox.shape = self.checkbox_shape.clone();
529        checkbox.side = self.side.clone();
530        checkbox.semantic_label = self.checkbox_semantic_label.clone();
531        checkbox
532    }
533}
534
535impl Debug for CheckboxListTile {
536    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
537        f.debug_struct("CheckboxListTile")
538            .field("value", &self.value)
539            .field("tristate", &self.tristate)
540            .field(
541                "on_changed",
542                &if self.on_changed.is_some() {
543                    "enabled"
544                } else {
545                    "disabled"
546                },
547            )
548            .finish_non_exhaustive()
549    }
550}
551
552impl StatelessWidget for CheckboxListTile {
553    fn key(&self) -> Option<&KeyRef> {
554        self.key.as_ref()
555    }
556
557    fn debug_check_constructor(&self) {
558        debug_assert!(self.tristate || self.value.is_some());
559        debug_assert!(self.is_three_line != Some(true) || self.subtitle.is_some());
560    }
561
562    fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef {
563        let mut control = ExcludeFocus::new(self.build_checkbox()).into_widget();
564        if self.checkbox_scale_factor != 1.0 {
565            control = Transform::scale(Some(self.checkbox_scale_factor), None, None)
566                .child(control)
567                .into_widget();
568        }
569
570        let list_tile_theme = ListTileTheme::of(app, context);
571        let effective_control_affinity = self
572            .control_affinity
573            .or(list_tile_theme.control_affinity)
574            .unwrap_or(ListTileControlAffinity::Platform);
575        let (leading, trailing) = match effective_control_affinity {
576            ListTileControlAffinity::Leading => (Some(control), self.secondary.clone()),
577            ListTileControlAffinity::Trailing | ListTileControlAffinity::Platform => {
578                (self.secondary.clone(), Some(control))
579            }
580        };
581
582        let theme = Theme::of(app, context);
583        let checkbox_theme = CheckboxTheme::of(app, context);
584        let mut states = WidgetStates::new();
585        if self.selected {
586            states.insert(WidgetState::Selected);
587        }
588        let effective_active_color = self
589            .active_color
590            .or_else(|| {
591                checkbox_theme
592                    .fill_color
593                    .as_ref()
594                    .and_then(|fill_color| fill_color.resolve(&states))
595            })
596            .unwrap_or(theme.color_scheme.secondary());
597        let mut list_tile = ListTile::new()
598            .selected_color(effective_active_color)
599            .enabled(self.enabled.unwrap_or(self.on_changed.is_some()))
600            .selected(self.selected)
601            .autofocus(self.autofocus);
602        list_tile.leading = leading;
603        list_tile.title = self.title.clone();
604        list_tile.subtitle = self.subtitle.clone();
605        list_tile.trailing = trailing;
606        list_tile.is_three_line = self.is_three_line;
607        list_tile.dense = self.dense;
608        list_tile.on_tap = if self.on_changed.is_some() {
609            Some(self.handle_value_change())
610        } else {
611            None
612        };
613        list_tile.content_padding = self.content_padding;
614        list_tile.shape = self.shape.clone();
615        list_tile.selected_tile_color = self.selected_tile_color;
616        list_tile.tile_color = self.tile_color;
617        list_tile.visual_density = self.visual_density;
618        list_tile.focus_node = self.focus_node.clone();
619        list_tile.states_controller = self.states_controller.clone();
620        list_tile.on_focus_change = self.on_focus_change.clone();
621        list_tile.enable_feedback = self.enable_feedback;
622        list_tile.horizontal_title_gap = self.horizontal_title_gap;
623        list_tile.min_vertical_padding = self.min_vertical_padding;
624        list_tile.min_leading_width = self.min_leading_width;
625        list_tile.min_tile_height = self.min_tile_height;
626        list_tile.title_alignment = self.title_alignment;
627        list_tile.internal_add_semantic_for_on_tap = self.internal_add_semantic_for_on_tap;
628        MergeSemantics::new().child(list_tile).into_widget()
629    }
630}
631
632#[cfg(test)]
633#[allow(deprecated)]
634pub(crate) mod tests {
635    use std::cell::{Cell, RefCell};
636    use waft_painting::ShapeBorder;
637    use waft_widgets::AnyFocusNode;
638
639    use waft_embedder::TextDirection;
640    use waft_embedder::{
641        Matrix4, Offset, PointerChange, RRect, Radius, Rect, Size, TargetPlatform,
642    };
643    use waft_foundation::K_IS_WEB;
644    use waft_painting::{
645        AlignmentGeometry, BorderRadiusGeometry, BorderSide, EdgeInsets, RoundedRectangleBorder,
646    };
647    use waft_services::SystemMouseCursors;
648    use waft_widgets::{
649        AnyElement, Center, Column, Container, Directionality, FocusHighlightStrategy, FocusNode,
650        GlobalKey, ListView, MouseRegion, SizedBox, StatefulBuilder, Text, UnfocusDisposition,
651        WidgetStateMouseCursor, WidgetStateProperty,
652    };
653
654    use waft_rendering::testing::{PaintCall, PaintedStyle};
655    use waft_widgets::testing::{TestPointer, WidgetTester, find, test_widgets};
656
657    use super::*;
658    use crate::checkbox::tests::{
659        assert_paints, checkbox_center, checkbox_size, hover, ignore, press,
660    };
661    use crate::checkbox_theme::CheckboxThemeData;
662    use crate::colors::Colors;
663    use crate::ink_well::InkWell;
664    use crate::list_tile::tests::{THIRTEEN_LINES, bare, m2, m3};
665    use crate::list_tile_theme::ListTileThemeData;
666    use crate::material::Material;
667    use crate::scaffold::Scaffold;
668    use crate::test_support::PaintInspection;
669    use crate::theme_data::ThemeData;
670    use crate::tooltip::tests::pump_app;
671
672    /// Dart's `wrap(child:)`: `MediaQuery(Directionality(ltr, Material(child)))`, under the
673    /// default theme.
674    pub(crate) fn pump_wrapped(
675        tester: &mut WidgetTester,
676        child: impl FnOnce(&mut App) -> WidgetRef,
677    ) {
678        let root = {
679            let mut app = tester.cell.borrow_mut();
680            let theme = m3(&app);
681            bare(theme, Material::new().child(child(&mut app)))
682        };
683        tester.pump_widget(root);
684    }
685
686    /// `MaterialApp(theme: theme, home: Material(child: child))`.
687    pub(crate) fn pump_in_material(
688        tester: &mut WidgetTester,
689        theme: impl FnOnce(&App) -> ThemeData,
690        child: impl FnOnce(&mut App) -> WidgetRef,
691    ) {
692        pump_app(tester, theme, |app| {
693            Material::new().child(child(app)).into_widget()
694        });
695    }
696
697    /// The `index`th element whose widget is a `W`: Dart's `find.byType(W).at(index)`.
698    pub(crate) fn nth<W: 'static>(tester: &WidgetTester, index: usize) -> AnyElement {
699        tester.element(find::by_type::<W>().at(index))
700    }
701
702    /// Dart's `tester.getRect(find.byType(W).at(index))`.
703    pub(crate) fn rect_of<W: 'static>(tester: &WidgetTester, index: usize) -> Rect {
704        tester.get_rect(nth::<W>(tester, index))
705    }
706
707    /// Dart's `tester.getRect(find.text(text))`, over `Text`s.
708    pub(crate) fn text_center(tester: &WidgetTester, text: &str) -> Offset {
709        let found = find::text(text).evaluate(tester);
710        tester.get_rect(found[0]).center()
711    }
712
713    /// Dart's `Focus.of(key.currentContext!)`.
714    pub(crate) fn focus_of(tester: &WidgetTester, key: &GlobalKey) -> AnyFocusNode {
715        let mut app = tester.cell.borrow_mut();
716        let context = key.current_context(&app).expect("mounted");
717        waft_widgets::Focus::of(&mut app, context, false, true)
718    }
719
720    pub(crate) fn has_primary_focus(tester: &WidgetTester, node: AnyFocusNode) -> bool {
721        node.has_primary_focus(&tester.cell.borrow())
722    }
723
724    pub(crate) fn new_focus_node(tester: &WidgetTester) -> FocusNodeRef {
725        FocusNode::new(&mut tester.cell.borrow_mut()).into_erased::<waft_widgets::AnyFocusNode>()
726    }
727
728    /// A focus-change callback that records the last value it was handed.
729    pub(crate) fn record_focus(got_focus: &Rc<Cell<bool>>) -> ValueChanged<bool> {
730        let got_focus = Rc::clone(got_focus);
731        Rc::new(move |_app, focused| got_focus.set(focused))
732    }
733
734    /// The `customBorder` of the tile's `InkWell`.
735    pub(crate) fn ink_well_custom_border(tester: &WidgetTester) -> Option<ShapeBorderRef> {
736        tester.widget(nth::<InkWell>(tester, 0), |ink_well: &InkWell| {
737            ink_well.ink_response.custom_border.clone()
738        })
739    }
740
741    /// The `enableFeedback` of the tile's `InkWell`: what reaches the feedback calls, the
742    /// click system sound waiting with `SystemSound`.
743    pub(crate) fn ink_well_enable_feedback(tester: &WidgetTester) -> bool {
744        tester.widget(nth::<InkWell>(tester, 0), |ink_well: &InkWell| {
745            ink_well.ink_response.enable_feedback
746        })
747    }
748
749    /// Dart's `RoundedRectangleBorder(borderRadius: BorderRadius.horizontal(right:
750    /// Radius.circular(100)))`.
751    pub(crate) fn right_rounded_border() -> RoundedRectangleBorder {
752        RoundedRectangleBorder::new(
753            BorderSide::NONE,
754            BorderRadiusGeometry::horizontal(None, Some(Radius::circular(100.0)), None, None),
755        )
756    }
757
758    /// Dart's `tester.getSize(find.byType(ListTile))`.
759    pub(crate) fn list_tile_size(tester: &WidgetTester) -> Size {
760        rect_of::<ListTile>(tester, 0).size()
761    }
762
763    /// One frame of an "isThreeLine" case: the `ThemeData.listTileTheme`'s, the ambient
764    /// `ListTileTheme`'s and the tile's `isThreeLine`.
765    pub(crate) type IsThreeLineFrame = (Option<bool>, Option<bool>, Option<bool>);
766
767    /// The frames of the "isThreeLine" cases: the `ThemeData.listTileTheme`'s, the ambient
768    /// `ListTileTheme`'s and the tile's `isThreeLine`, and whether the tiles lay out in three
769    /// lines.
770    pub(crate) const IS_THREE_LINE_FRAMES: [(IsThreeLineFrame, bool); 11] = [
771        ((None, None, None), false),
772        ((Some(true), None, None), true),
773        ((Some(false), Some(true), None), true),
774        ((Some(true), Some(false), None), false),
775        ((None, None, Some(true)), true),
776        ((None, Some(true), Some(false)), false),
777        ((Some(true), None, Some(false)), false),
778        ((Some(true), Some(true), Some(false)), false),
779        ((None, Some(false), Some(true)), true),
780        ((Some(false), None, Some(true)), true),
781        ((Some(false), Some(false), Some(true)), true),
782    ];
783
784    /// One frame of an "isThreeLine" case on a fresh tester (Dart's `MaterialApp(key:
785    /// UniqueKey())`): `tile(is_three_line, subtitle)` twice in a `ListView`, the first with
786    /// thirteen lines of subtitle; answers the two tiles' rects and their controls' (`C`).
787    pub(crate) fn is_three_line_rects<C: 'static, W: 'static>(
788        tester: &mut WidgetTester,
789        platform: TargetPlatform,
790        (theme_data_is_three_line, theme_is_three_line, is_three_line): IsThreeLineFrame,
791        tile: fn(Option<bool>, &str) -> WidgetRef,
792    ) -> [Rect; 4] {
793        crate::list_tile::tests::pump_unique_app(
794            tester,
795            |app| {
796                let mut theme = ThemeData::builder().platform(platform);
797                if let Some(is_three_line) = theme_data_is_three_line {
798                    theme = theme
799                        .list_tile_theme(ListTileThemeData::new().is_three_line(is_three_line));
800                }
801                theme.build(app)
802            },
803            |_app| {
804                let list = ListView::new().children([
805                    tile(is_three_line, THIRTEEN_LINES),
806                    tile(is_three_line, "A"),
807                ]);
808                let mut theme = ListTileTheme::new(list);
809                if let Some(is_three_line) = theme_is_three_line {
810                    theme = theme.data(ListTileThemeData::new().is_three_line(is_three_line));
811                }
812                Material::new().child(theme).into_widget()
813            },
814        );
815        [
816            rect_of::<W>(tester, 0),
817            rect_of::<C>(tester, 0),
818            rect_of::<W>(tester, 1),
819            rect_of::<C>(tester, 1),
820        ]
821    }
822
823    /// The rects an "isThreeLine" case expects of two tiles 300 and 72 (two-line) or 88
824    /// (three-line) high whose `control_size` control sits at `left`, and at `two_line_tops`
825    /// when two-line.
826    pub(crate) fn expected_three_line_rects(
827        three_line: bool,
828        left: f64,
829        control_size: Size,
830        two_line_tops: [f64; 2],
831    ) -> [Rect; 4] {
832        const HEIGHT: f64 = 300.0;
833        let (second_height, tops) = if three_line {
834            (88.0, [8.0, HEIGHT + 8.0])
835        } else {
836            (72.0, two_line_tops)
837        };
838        [
839            Rect::from_ltwh(0.0, 0.0, 800.0, HEIGHT),
840            Rect::from_ltwh(left, tops[0], control_size.width(), control_size.height()),
841            Rect::from_ltwh(0.0, HEIGHT, 800.0, second_height),
842            Rect::from_ltwh(left, tops[1], control_size.width(), control_size.height()),
843        ]
844    }
845
846    /// One frame of the spacing cases on a fresh tester: `MaterialApp(theme:,
847    /// home: Directionality(text_direction, Material(ListTileTheme(data:,
848    /// Container(alignment: topLeft, child: tile)))))`.
849    pub(crate) fn spacing_frame(
850        tester: &mut WidgetTester,
851        theme: fn(&App) -> ThemeData,
852        text_direction: TextDirection,
853        data: ListTileThemeData,
854        tile: WidgetRef,
855    ) {
856        pump_app(tester, theme, |_app| {
857            Directionality::new(
858                text_direction,
859                Material::new().child(
860                    ListTileTheme::new(
861                        Container::new()
862                            .alignment(AlignmentGeometry::TOP_LEFT)
863                            .child(tile),
864                    )
865                    .data(data),
866                ),
867            )
868            .into_widget()
869        });
870    }
871
872    /// Where the `title` starts (LTR) or ends (RTL).
873    pub(crate) fn title_edge(tester: &WidgetTester, text_direction: TextDirection) -> f64 {
874        let title = tester.get_rect(find::text("title"));
875        match text_direction {
876            TextDirection::Ltr => title.left,
877            TextDirection::Rtl => title.right,
878        }
879    }
880
881    /// The frames of the gap and width cases: the theme's value and the tile's.
882    pub(crate) const THEME_AND_WIDGET_FRAMES: [(Option<f64>, Option<f64>); 3] = [
883        (None, Some(0.0)),
884        (Some(0.0), None),
885        (Some(10.0), Some(0.0)),
886    ];
887
888    /// The frames of the cases that set 60 or 80: the theme's value and the tile's.
889    pub(crate) fn theme_and_widget_frames(value: f64) -> [(Option<f64>, Option<f64>); 3] {
890        [
891            (None, Some(value)),
892            (Some(value), None),
893            (Some(0.0), Some(value)),
894        ]
895    }
896
897    /// The vertical offsets of the control `C` and of `secondary_key`'s top right from the
898    /// tile's top: what the "titleAlignment" cases compare.
899    pub(crate) fn title_alignment_offsets<C: 'static>(
900        tester: &WidgetTester,
901        secondary_key: &GlobalKey,
902    ) -> (f64, f64) {
903        let tile = rect_of::<ListTile>(tester, 0);
904        let control = rect_of::<C>(tester, 0);
905        let secondary = tester.get_rect(secondary_key);
906        (control.top - tile.top, secondary.top - tile.top)
907    }
908
909    /// "titleAlignment position with title widget" and "... with title and subtitle widgets"
910    /// for a tile `make(title_alignment, secondary)` with the control `C` leading: the expected
911    /// offsets of each alignment given the tile's and the control's heights.
912    pub(crate) fn check_title_alignment<C: 'static>(
913        tester: &mut WidgetTester,
914        make: impl Fn(Option<ListTileTitleAlignment>, WidgetRef, bool) -> WidgetRef,
915        with_subtitle: bool,
916    ) {
917        const SECONDARY_HEIGHT: f64 = 24.0;
918        // The default vertical padding for material 3 is 8.0.
919        const MIN_VERTICAL_PADDING: f64 = 8.0;
920        let secondary_key = GlobalKey::new();
921        let frame = |tester: &mut WidgetTester, title_alignment| {
922            let secondary = SizedBox::new()
923                .key(secondary_key.clone().into())
924                .width(24.0)
925                .height(SECONDARY_HEIGHT)
926                .into_widget();
927            let tile = make(title_alignment, secondary, with_subtitle);
928            pump_in_material(tester, m3, |_app| Center::new().child(tile).into_widget());
929            assert_eq!(
930                tester.widget(nth::<ListTile>(tester, 0), |tile: &ListTile| {
931                    tile.title_alignment
932                }),
933                title_alignment
934            );
935            title_alignment_offsets::<C>(tester, &secondary_key)
936        };
937
938        let offsets = frame(tester, None);
939        let tile_height = list_tile_size(tester).height();
940        let control_height = rect_of::<C>(tester, 0).height();
941        // Leading and trailing widgets are centered vertically in the tile.
942        let center = (
943            tile_height / 2.0 - control_height / 2.0,
944            tile_height / 2.0 - SECONDARY_HEIGHT / 2.0,
945        );
946        assert_eq!(offsets, center);
947        assert_eq!(
948            frame(tester, Some(ListTileTitleAlignment::ThreeLine)),
949            center
950        );
951        let title_height = if with_subtitle {
952            // Leading and trailing widgets are positioned 16.0 pixels below the top of the
953            // title widget.
954            (16.0, 16.0)
955        } else {
956            ((tile_height - control_height) / 2.0, center.1)
957        };
958        assert_eq!(
959            frame(tester, Some(ListTileTitleAlignment::TitleHeight)),
960            title_height
961        );
962        // Leading and trailing widgets are placed minVerticalPadding below the top of the
963        // title widget.
964        assert_eq!(
965            frame(tester, Some(ListTileTitleAlignment::Top)),
966            (MIN_VERTICAL_PADDING, MIN_VERTICAL_PADDING)
967        );
968        assert_eq!(frame(tester, Some(ListTileTitleAlignment::Center)), center);
969        // Leading and trailing widgets are placed minVerticalPadding above the bottom of the
970        // subtitle widget.
971        assert_eq!(
972            frame(tester, Some(ListTileTitleAlignment::Bottom)),
973            (
974                tile_height - MIN_VERTICAL_PADDING - control_height,
975                tile_height - MIN_VERTICAL_PADDING - SECONDARY_HEIGHT
976            )
977        );
978    }
979
980    /// A tile whose value a `StatefulBuilder` keeps and whose `on_changed` sets.
981    fn stateful_tile(
982        value: &Rc<Cell<Option<bool>>>,
983        configure: impl Fn(CheckboxListTile) -> CheckboxListTile + 'static,
984    ) -> WidgetRef {
985        let value = Rc::clone(value);
986        StatefulBuilder::new(move |_app, _context, set_state| {
987            let value_now = Rc::clone(&value);
988            configure(CheckboxListTile::new(
989                value.get(),
990                Some(Rc::new(move |app: &mut App, new_value: Option<bool>| {
991                    let value = Rc::clone(&value_now);
992                    set_state(app, &mut |_app| value.set(new_value));
993                })),
994            ))
995            .into_widget()
996        })
997        .into_widget()
998    }
999
1000    fn fill_when_selected(color: Option<Color>) -> CheckboxThemeData {
1001        CheckboxThemeData::new().fill_color(<dyn WidgetStateProperty<Option<Color>>>::resolve_with(
1002            move |states| {
1003                if states.contains(&WidgetState::Selected) {
1004                    color
1005                } else {
1006                    None
1007                }
1008            },
1009        ))
1010    }
1011
1012    #[test]
1013    fn checkbox_list_tile_control_test() {
1014        test_widgets(|tester| {
1015            let log = Rc::new(RefCell::new(Vec::new()));
1016            let on_changed: ValueChanged<Option<bool>> = {
1017                let log = Rc::clone(&log);
1018                Rc::new(move |_app, value| log.borrow_mut().push(Some(value)))
1019            };
1020            pump_wrapped(tester, |_app| {
1021                CheckboxListTile::new(Some(true), Some(on_changed))
1022                    .title(Text::new("Hello"))
1023                    .into_widget()
1024            });
1025            let hello = text_center(tester, "Hello");
1026            tester.tap_at(hello, 1);
1027            log.borrow_mut().push(None);
1028            let checkbox = checkbox_center(tester);
1029            tester.tap_at(checkbox, 2);
1030            assert_eq!(*log.borrow(), [Some(Some(false)), None, Some(Some(false))]);
1031        });
1032    }
1033
1034    #[test]
1035    fn checkbox_list_tile_forwards_states_controller_to_list_tile() {
1036        test_widgets(|tester| {
1037            let controller = WidgetStatesController::new(&mut tester.cell.borrow_mut(), None);
1038            pump_in_material(tester, m3, |_app| {
1039                CheckboxListTile::new(Some(true), ignore())
1040                    .title(Text::new("Checkbox"))
1041                    .states_controller(controller.clone())
1042                    .into_widget()
1043            });
1044            let forwarded = tester.widget(nth::<ListTile>(tester, 0), |tile: &ListTile| {
1045                tile.states_controller.clone()
1046            });
1047            assert_eq!(forwarded, Some(controller));
1048        });
1049    }
1050
1051    fn check_color_case(theme: fn(&App) -> ThemeData, check_box_border_color: Color) {
1052        test_widgets(|tester| {
1053            for check_color in [None, Some(Color::new(0xFF000000))] {
1054                pump_in_material(tester, theme, |_app| {
1055                    let mut tile = CheckboxListTile::new(Some(true), ignore());
1056                    tile.check_color = check_color;
1057                    tile.into_widget()
1058                });
1059                tester.pump_and_settle();
1060                assert_paints(
1061                    tester,
1062                    &[
1063                        PaintCall::rrect(Some(check_box_border_color)),
1064                        PaintCall::path(Some(check_color.unwrap_or(Color::new(0xFFFFFFFF)))),
1065                    ],
1066                );
1067            }
1068        });
1069    }
1070
1071    #[test]
1072    fn material2_checkbox_list_tile_check_color_test() {
1073        test_widgets(|_| {
1074            check_color_case(m2, Color::new(0xff2196f3));
1075        });
1076    }
1077
1078    #[test]
1079    fn material3_checkbox_list_tile_check_color_test() {
1080        test_widgets(|_| {
1081            check_color_case(m3, Color::new(0xff6750a4));
1082        });
1083    }
1084
1085    #[test]
1086    fn checkbox_list_tile_active_color_test() {
1087        test_widgets(|tester| {
1088            for (active_color, expected) in [
1089                (None, Color::new(0xFF000000)),
1090                (Some(Color::new(0xFFFFFFFF)), Color::new(0xFFFFFFFF)),
1091            ] {
1092                pump_wrapped(tester, |app| {
1093                    let theme = ThemeData::builder()
1094                        .checkbox_theme(fill_when_selected(Some(Color::new(0xFF000000))))
1095                        .build(app);
1096                    let mut tile = CheckboxListTile::new(Some(true), ignore());
1097                    tile.active_color = active_color;
1098                    crate::theme::Theme::new(theme, tile).into_widget()
1099                });
1100                tester.pump_and_settle();
1101                assert_paints(tester, &[PaintCall::rrect(Some(expected))]);
1102            }
1103        });
1104    }
1105
1106    #[test]
1107    fn checkbox_list_tile_can_autofocus_unless_disabled() {
1108        test_widgets(|tester| {
1109            let child_key = GlobalKey::new();
1110            for (on_changed, focused) in [(ignore(), true), (None, false)] {
1111                let key = child_key.clone();
1112                pump_wrapped(tester, move |_app| {
1113                    CheckboxListTile::new(Some(true), on_changed)
1114                        .title(Text::new("Hello").key(key.into()))
1115                        .autofocus(true)
1116                        .into_widget()
1117                });
1118                tester.pump();
1119                let node = focus_of(tester, &child_key);
1120                assert_eq!(has_primary_focus(tester, node), focused);
1121            }
1122        });
1123    }
1124
1125    #[test]
1126    fn checkbox_list_tile_content_padding_test() {
1127        test_widgets(|tester| {
1128            pump_wrapped(tester, |_app| {
1129                Center::new()
1130                    .child(
1131                        CheckboxListTile::new(Some(false), None)
1132                            .title(Text::new("Title"))
1133                            .content_padding(EdgeInsets::from_ltrb(10.0, 18.0, 4.0, 2.0)),
1134                    )
1135                    .into_widget()
1136            });
1137            let padding_rect = rect_of::<waft_widgets::SafeArea>(tester, 0);
1138            let checkbox_rect = rect_of::<Checkbox>(tester, 0);
1139            let title_rect = tester.get_rect(find::text("Title"));
1140            let taller = if checkbox_rect.height() > title_rect.height() {
1141                checkbox_rect
1142            } else {
1143                title_rect
1144            };
1145
1146            // Check the offsets of Checkbox and title after padding is applied.
1147            assert_eq!(padding_rect.right, checkbox_rect.right + 4.0);
1148            assert_eq!(padding_rect.left, title_rect.left - 10.0);
1149
1150            // Calculate the remaining height from the default ListTile height.
1151            let remaining_height = 56.0 - taller.height();
1152            assert_eq!(padding_rect.top, taller.top - remaining_height / 2.0 - 18.0);
1153            assert_eq!(
1154                padding_rect.bottom,
1155                taller.bottom + remaining_height / 2.0 + 2.0
1156            );
1157        });
1158    }
1159
1160    #[test]
1161    fn checkbox_list_tile_tristate_test() {
1162        test_widgets(|tester| {
1163            let value = Rc::new(Cell::new(Some(false)));
1164            let tristate = Rc::new(Cell::new(false));
1165            let host = {
1166                let tristate = Rc::clone(&tristate);
1167                stateful_tile(&value, move |tile| {
1168                    tile.title(Text::new("Title")).tristate(tristate.get())
1169                })
1170            };
1171            pump_wrapped(tester, |_app| host);
1172            let shown = |tester: &WidgetTester| {
1173                tester.widget(nth::<Checkbox>(tester, 0), |checkbox: &Checkbox| {
1174                    checkbox.value
1175                })
1176            };
1177            let tap_checkbox = |tester: &mut WidgetTester| {
1178                let at = checkbox_center(tester);
1179                tester.tap_at(at, 1);
1180                tester.pump_and_settle();
1181            };
1182            let tap_tile = |tester: &mut WidgetTester| {
1183                let at = rect_of::<ListTile>(tester, 0).center();
1184                tester.tap_at(at, 1);
1185                tester.pump_and_settle();
1186            };
1187            assert_eq!(shown(tester), Some(false));
1188
1189            // Tap the checkbox when tristate is disabled.
1190            for expected in [Some(true), Some(false)] {
1191                tap_checkbox(tester);
1192                assert_eq!(value.get(), expected);
1193            }
1194            // Tap the listTile when tristate is disabled.
1195            for expected in [Some(true), Some(false)] {
1196                tap_tile(tester);
1197                assert_eq!(value.get(), expected);
1198            }
1199
1200            // Enable tristate: Dart's flag is read by the next build, which a tap triggers.
1201            tristate.set(true);
1202            tester.pump_and_settle();
1203            assert_eq!(shown(tester), Some(false));
1204
1205            // Tap the checkbox when tristate is enabled.
1206            for expected in [Some(true), None, Some(false)] {
1207                tap_checkbox(tester);
1208                assert_eq!(value.get(), expected);
1209            }
1210            // Tap the listTile when tristate is enabled.
1211            for expected in [Some(true), None, Some(false)] {
1212                tap_tile(tester);
1213                assert_eq!(value.get(), expected);
1214            }
1215        });
1216    }
1217
1218    #[test]
1219    fn checkbox_list_tile_respects_shape() {
1220        test_widgets(|tester| {
1221            pump_wrapped(tester, |_app| {
1222                CheckboxListTile::new(Some(false), None)
1223                    .title(Text::new("Title"))
1224                    .shape(ShapeBorderRef::new(right_rounded_border()))
1225                    .into_widget()
1226            });
1227            let shape: ShapeBorderRef = ShapeBorderRef::new(right_rounded_border());
1228            assert!(ink_well_custom_border(tester).as_deref() == Some(&*shape));
1229        });
1230    }
1231
1232    #[test]
1233    fn checkbox_list_tile_respects_tile_color() {
1234        test_widgets(|tester| {
1235            let tile_color = Colors::RED.shade500();
1236            pump_wrapped(tester, |_app| {
1237                Center::new()
1238                    .child(
1239                        CheckboxListTile::new(Some(false), None)
1240                            .title(Text::new("Title"))
1241                            .tile_color(tile_color),
1242                    )
1243                    .into_widget()
1244            });
1245            waft_rendering::testing::assert_paints(
1246                tester.ink_list().ops(),
1247                &[waft_rendering::testing::PaintCall::rect(Some(tile_color))],
1248            );
1249        });
1250    }
1251
1252    #[test]
1253    fn checkbox_list_tile_respects_selected_tile_color() {
1254        test_widgets(|tester| {
1255            let selected_tile_color = Colors::GREEN.shade500();
1256            pump_wrapped(tester, |_app| {
1257                Center::new()
1258                    .child(
1259                        CheckboxListTile::new(Some(false), None)
1260                            .title(Text::new("Title"))
1261                            .selected(true)
1262                            .selected_tile_color(selected_tile_color),
1263                    )
1264                    .into_widget()
1265            });
1266            waft_rendering::testing::assert_paints(
1267                tester.ink_list().ops(),
1268                &[waft_rendering::testing::PaintCall::rect(Some(
1269                    selected_tile_color,
1270                ))],
1271            );
1272        });
1273    }
1274
1275    #[test]
1276    fn checkbox_list_tile_selected_item_text_color() {
1277        test_widgets(|tester| {
1278            // Regression test for https://github.com/flutter/flutter/pull/76908
1279            const ACTIVE_COLOR: Color = Color::new(0xff00ff00);
1280            for (active_color, fill_color) in
1281                [(None, Some(ACTIVE_COLOR)), (Some(ACTIVE_COLOR), None)]
1282            {
1283                pump_app(
1284                    tester,
1285                    move |app| {
1286                        ThemeData::builder()
1287                            .checkbox_theme(fill_when_selected(fill_color))
1288                            .build(app)
1289                    },
1290                    move |_app| {
1291                        let mut tile = CheckboxListTile::new(Some(true), ignore())
1292                            .selected(true)
1293                            .title(Text::new("title"));
1294                        tile.active_color = active_color;
1295                        Scaffold::new()
1296                            .body(Center::new().child(tile))
1297                            .into_widget()
1298                    },
1299                );
1300                assert_eq!(tester.text_color("title"), ACTIVE_COLOR);
1301            }
1302        });
1303    }
1304
1305    #[test]
1306    fn checkbox_list_tile_respects_checkbox_shape_and_side() {
1307        test_widgets(|tester| {
1308            let border = || {
1309                RoundedRectangleBorder::new(
1310                    BorderSide::NONE,
1311                    BorderRadiusGeometry::all(Radius::circular(5.0)),
1312                )
1313            };
1314            let rrect = |l: f64, t: f64, r: f64, b: f64, radius: f64| {
1315                RRect::from_ltrbr(l, t, r, b, Radius::circular(radius))
1316            };
1317            let frames = [
1318                (
1319                    BorderSide {
1320                        color: Color::new(0xfff44336),
1321                        ..BorderSide::default()
1322                    },
1323                    rrect(12.0, 12.0, 28.0, 28.0, 4.0),
1324                ),
1325                (
1326                    BorderSide {
1327                        width: 4.0,
1328                        color: Color::new(0xff424242),
1329                        ..BorderSide::default()
1330                    },
1331                    rrect(15.0, 15.0, 25.0, 25.0, 1.0),
1332                ),
1333            ];
1334            for (side, inner) in frames {
1335                pump_in_material(tester, m3, move |_app| {
1336                    Center::new()
1337                        .child(
1338                            CheckboxListTile::new(Some(false), ignore())
1339                                .side(side)
1340                                .checkbox_shape(OutlinedBorderRef::new(border())),
1341                        )
1342                        .into_widget()
1343                });
1344                let side_any: AnyBorderSide = side.into();
1345                tester.widget(
1346                    nth::<CheckboxListTile>(tester, 0),
1347                    |tile: &CheckboxListTile| {
1348                        assert!(tile.side.as_ref() == Some(&side_any));
1349                        let shape: &dyn ShapeBorder =
1350                            tile.checkbox_shape.as_deref().expect("a shape");
1351                        assert!(shape == &border() as &dyn ShapeBorder);
1352                    },
1353                );
1354                tester.widget(nth::<Checkbox>(tester, 0), |checkbox: &Checkbox| {
1355                    assert!(checkbox.side.as_ref() == Some(&side_any));
1356                    let shape: &dyn ShapeBorder = checkbox.shape.as_deref().expect("a shape");
1357                    assert!(shape == &border() as &dyn ShapeBorder);
1358                });
1359                assert_paints(
1360                    tester,
1361                    &[PaintCall::drrect_between(
1362                        rrect(11.0, 11.0, 29.0, 29.0, 5.0),
1363                        inner,
1364                        Some(side.color),
1365                    )],
1366                );
1367            }
1368        });
1369    }
1370
1371    #[test]
1372    fn checkbox_list_tile_respects_visual_density() {
1373        test_widgets(|tester| {
1374            pump_wrapped(tester, |_app| {
1375                Center::new()
1376                    .child(
1377                        CheckboxListTile::new(Some(false), ignore())
1378                            .autofocus(true)
1379                            .visual_density(VisualDensity::STANDARD),
1380                    )
1381                    .into_widget()
1382            });
1383            tester.pump_and_settle();
1384            assert_eq!(
1385                rect_of::<CheckboxListTile>(tester, 0).size(),
1386                Size::new(800.0, 56.0)
1387            );
1388        });
1389    }
1390
1391    #[test]
1392    fn checkbox_list_tile_respects_focus_node() {
1393        test_widgets(|tester| {
1394            let child_key = GlobalKey::new();
1395            let key = child_key.clone();
1396            pump_wrapped(tester, move |_app| {
1397                Center::new()
1398                    .child(
1399                        CheckboxListTile::new(Some(false), ignore())
1400                            .title(Text::new("A").key(key.into())),
1401                    )
1402                    .into_widget()
1403            });
1404            tester.pump();
1405            let tile_node = focus_of(tester, &child_key);
1406            tile_node.request_focus(&mut tester.cell.borrow_mut(), None);
1407            tester.pump(); // Let the focus take effect.
1408            let node = focus_of(tester, &child_key);
1409            assert!(has_primary_focus(tester, node));
1410            assert!(has_primary_focus(tester, tile_node));
1411        });
1412    }
1413
1414    /// Dart's "onFocusChange callback" case for a tile `make(focus_node, on_focus_change)`.
1415    pub(crate) fn check_on_focus_change(
1416        tester: &mut WidgetTester,
1417        make: impl FnOnce(FocusNodeRef, ValueChanged<bool>) -> WidgetRef,
1418    ) {
1419        let node = new_focus_node(tester);
1420        let got_focus = Rc::new(Cell::new(false));
1421        let tile = make(node.clone(), record_focus(&got_focus));
1422        pump_in_material(tester, m3, |_app| tile);
1423
1424        node.request_focus(&mut tester.cell.borrow_mut(), None);
1425        tester.pump();
1426        assert!(got_focus.get());
1427        assert!(node.has_focus(&tester.cell.borrow_mut()));
1428
1429        node.unfocus(&mut tester.cell.borrow_mut(), UnfocusDisposition::Scope);
1430        tester.pump();
1431        assert!(!got_focus.get());
1432        assert!(!node.has_focus(&tester.cell.borrow_mut()));
1433    }
1434
1435    #[test]
1436    fn checkbox_list_tile_on_focus_change_callback() {
1437        test_widgets(|tester| {
1438            check_on_focus_change(tester, |node, on_focus_change| {
1439                CheckboxListTile::new(Some(true), ignore())
1440                    .focus_node(node)
1441                    .on_focus_change(on_focus_change)
1442                    .into_widget()
1443            });
1444        });
1445    }
1446
1447    #[test]
1448    fn checkbox_list_tile_can_be_disabled() {
1449        test_widgets(|tester| {
1450            let value = Rc::new(Cell::new(Some(false)));
1451            let enabled = Rc::new(Cell::new(true));
1452            let host = {
1453                let value = Rc::clone(&value);
1454                let enabled = Rc::clone(&enabled);
1455                StatefulBuilder::new(move |_app, _context, set_state| {
1456                    let (value_now, enabled_now) = (Rc::clone(&value), Rc::clone(&enabled));
1457                    CheckboxListTile::new(
1458                        value.get(),
1459                        Some(Rc::new(move |app: &mut App, new_value: Option<bool>| {
1460                            let (value, enabled) = (Rc::clone(&value_now), Rc::clone(&enabled_now));
1461                            set_state(app, &mut |_app| {
1462                                value.set(new_value);
1463                                enabled.set(!enabled.get());
1464                            });
1465                        })),
1466                    )
1467                    .title(Text::new("Title"))
1468                    .enabled(enabled.get())
1469                    .into_widget()
1470                })
1471                .into_widget()
1472            };
1473            pump_wrapped(tester, |_app| host);
1474            let shown = |tester: &WidgetTester| {
1475                tester.widget(nth::<Checkbox>(tester, 0), |checkbox: &Checkbox| {
1476                    checkbox.value
1477                })
1478            };
1479            // verify initial values
1480            assert_eq!(shown(tester), Some(false));
1481            assert!(enabled.get());
1482
1483            // Tap the checkbox to disable CheckboxListTile
1484            let at = checkbox_center(tester);
1485            tester.tap_at(at, 1);
1486            tester.pump_and_settle();
1487            assert_eq!(shown(tester), Some(true));
1488            assert!(!enabled.get());
1489            tester.tap_at(at, 2);
1490            tester.pump_and_settle();
1491            assert_eq!(shown(tester), Some(true));
1492        });
1493    }
1494
1495    pub(crate) fn selected_grab_mouse_cursor() -> MouseCursorRef {
1496        WidgetStateMouseCursor::resolve_with(
1497            |states| {
1498                if states.contains(&WidgetState::Selected) {
1499                    SystemMouseCursors::GRAB.into()
1500                } else {
1501                    SystemMouseCursors::BASIC.into()
1502                }
1503            },
1504            Some("_SelectedGrabMouseCursor()"),
1505        )
1506        .into()
1507    }
1508
1509    /// `wrap(child: MouseRegion(cursor: forbidden, child: tile))`.
1510    pub(crate) fn pump_in_forbidden_region(tester: &mut WidgetTester, tile: WidgetRef) {
1511        pump_wrapped(tester, |_app| {
1512            MouseRegion::new()
1513                .cursor(SystemMouseCursors::FORBIDDEN.into())
1514                .child(tile)
1515                .into_widget()
1516        });
1517    }
1518
1519    #[test]
1520    fn checkbox_list_tile_respects_mouse_cursor_when_hovered() {
1521        test_widgets(|tester| {
1522            // Test Checkbox() constructor
1523            pump_in_forbidden_region(
1524                tester,
1525                CheckboxListTile::new(Some(true), ignore())
1526                    .mouse_cursor(MouseCursorRef::from(SystemMouseCursors::TEXT))
1527                    .into_widget(),
1528            );
1529            let mut gesture = TestPointer::mouse(1, 0);
1530            let center = checkbox_center(tester);
1531            tester.add_pointer(&mut gesture, center);
1532            tester.pump();
1533            tester.move_to(&mut gesture, center, false);
1534            assert_eq!(tester.active_cursor(1), SystemMouseCursors::TEXT.into());
1535
1536            // Test default cursor
1537            pump_wrapped(tester, |_app| {
1538                CheckboxListTile::new(Some(true), ignore()).into_widget()
1539            });
1540            let expected: MouseCursorRef = if K_IS_WEB {
1541                SystemMouseCursors::CLICK.into()
1542            } else {
1543                SystemMouseCursors::BASIC.into()
1544            };
1545            assert_eq!(Some(tester.active_cursor(1)), Some(expected));
1546
1547            // Test default cursor when disabled
1548            pump_in_forbidden_region(
1549                tester,
1550                CheckboxListTile::new(Some(true), None).into_widget(),
1551            );
1552            let center = checkbox_center(tester);
1553            tester.move_to(&mut gesture, center, false);
1554            assert_eq!(tester.active_cursor(1), SystemMouseCursors::BASIC.into());
1555
1556            // Test cursor when tristate
1557            pump_in_forbidden_region(
1558                tester,
1559                CheckboxListTile::new(None, None)
1560                    .tristate(true)
1561                    .mouse_cursor(selected_grab_mouse_cursor())
1562                    .into_widget(),
1563            );
1564            assert_eq!(tester.active_cursor(1), SystemMouseCursors::GRAB.into());
1565
1566            tester.pump_and_settle();
1567            tester.send(&gesture, PointerChange::Remove);
1568        });
1569    }
1570
1571    #[test]
1572    fn checkbox_list_tile_respects_fill_color_in_enabled_disabled_states() {
1573        test_widgets(|tester| {
1574            const ACTIVE_ENABLED_FILL_COLOR: Color = Color::new(0xFF000001);
1575            const ACTIVE_DISABLED_FILL_COLOR: Color = Color::new(0xFF000002);
1576            let fill_color = <dyn WidgetStateProperty<Option<Color>>>::resolve_with(|states| {
1577                if states.contains(&WidgetState::Disabled) {
1578                    return Some(ACTIVE_DISABLED_FILL_COLOR);
1579                }
1580                Some(ACTIVE_ENABLED_FILL_COLOR)
1581            });
1582            for (enabled, expected) in [
1583                (true, ACTIVE_ENABLED_FILL_COLOR),
1584                (false, ACTIVE_DISABLED_FILL_COLOR),
1585            ] {
1586                let fill_color = Rc::clone(&fill_color);
1587                pump_wrapped(tester, move |_app| {
1588                    CheckboxListTile::new(Some(true), if enabled { ignore() } else { None })
1589                        .fill_color(fill_color)
1590                        .into_widget()
1591                });
1592                tester.pump_and_settle();
1593                assert_paints(tester, &[PaintCall::rrect(Some(expected))]);
1594            }
1595        });
1596    }
1597
1598    #[test]
1599    fn checkbox_list_tile_respects_fill_color_in_hovered_state() {
1600        test_widgets(|tester| {
1601            tester.set_highlight_strategy(FocusHighlightStrategy::AlwaysTraditional);
1602            const HOVERED_FILL_COLOR: Color = Color::new(0xFF000001);
1603            let fill_color = <dyn WidgetStateProperty<Option<Color>>>::resolve_with(|states| {
1604                if states.contains(&WidgetState::Hovered) {
1605                    return Some(HOVERED_FILL_COLOR);
1606                }
1607                Some(Colors::TRANSPARENT)
1608            });
1609            pump_wrapped(tester, |_app| {
1610                CheckboxListTile::new(Some(true), ignore())
1611                    .fill_color(fill_color)
1612                    .into_widget()
1613            });
1614            tester.pump_and_settle();
1615
1616            // Start hovering
1617            let gesture = hover(tester);
1618            tester.pump_and_settle();
1619            assert_paints(tester, &[PaintCall::rrect(Some(HOVERED_FILL_COLOR))]);
1620            tester.send(&gesture, PointerChange::Remove);
1621        });
1622    }
1623
1624    #[test]
1625    fn checkbox_list_tile_respects_hover_color() {
1626        test_widgets(|tester| {
1627            tester.set_highlight_strategy(FocusHighlightStrategy::AlwaysTraditional);
1628            let value = Rc::new(Cell::new(Some(true)));
1629            let orange = Colors::ORANGE.shade500();
1630            let frame = |tester: &mut WidgetTester, enabled: bool| {
1631                let host = stateful_tile(&value, move |mut tile| {
1632                    if !enabled {
1633                        tile.on_changed = None;
1634                    }
1635                    tile.hover_color(orange)
1636                });
1637                pump_wrapped(tester, |_app| host);
1638                tester.pump_and_settle();
1639            };
1640            let unhovered = [PaintCall::rrect(Some(
1641                m3(&tester.cell.borrow()).color_scheme.primary(),
1642            ))];
1643            frame(tester, true);
1644            assert_paints(
1645                tester,
1646                &[PaintCall::Path {
1647                    color: None,
1648                    style: Some(PaintedStyle::Stroke(Some(2.0))),
1649                    includes: vec![],
1650                    excludes: vec![],
1651                }],
1652            );
1653            assert_paints(tester, &unhovered);
1654
1655            // Start hovering
1656            let gesture = hover(tester);
1657            frame(tester, true);
1658            assert_paints(
1659                tester,
1660                &[
1661                    PaintCall::circle(Some(orange)),
1662                    PaintCall::Path {
1663                        color: None,
1664                        style: Some(PaintedStyle::Stroke(Some(2.0))),
1665                        includes: vec![],
1666                        excludes: vec![],
1667                    },
1668                ],
1669            );
1670
1671            // Check what happens when disabled.
1672            frame(tester, false);
1673            crate::checkbox::tests::assert_does_not_paint(
1674                tester,
1675                &[PaintCall::circle(Some(orange))],
1676            );
1677            assert_paints(
1678                tester,
1679                &[PaintCall::Path {
1680                    color: None,
1681                    style: Some(PaintedStyle::Stroke(Some(2.0))),
1682                    includes: vec![],
1683                    excludes: vec![],
1684                }],
1685            );
1686            tester.send(&gesture, PointerChange::Remove);
1687        });
1688    }
1689
1690    /// Dart's `Material.of(tester.element(find.byType(Checkbox)))`: the material the checkbox
1691    /// paints into, which Dart's `paints` matcher paints with its subtree.
1692    fn checkbox_material(tester: &WidgetTester) -> waft_rendering::AnyRenderObject {
1693        let checkbox = nth::<Checkbox>(tester, 0);
1694        let app = tester.cell.borrow();
1695        let ink = waft_widgets::LookupBoundary::find_ancestor_render_object_of_type::<
1696            crate::material::RenderInkFeatures,
1697        >(&app, checkbox)
1698        .expect("a Material above the checkbox");
1699        waft_rendering::RenderBox::as_object(ink)
1700    }
1701
1702    #[test]
1703    fn material2_checkbox_list_tile_respects_overlay_color_in_active_pressed_hovered_states() {
1704        test_widgets(|tester| {
1705            use crate::radio::tests::{CircleArguments, assert_paints, circle};
1706
1707            tester.set_highlight_strategy(FocusHighlightStrategy::AlwaysTraditional);
1708            const FILL_COLOR: Color = Color::new(0xFF000000);
1709            const ACTIVE_PRESSED_OVERLAY_COLOR: Color = Color::new(0xFF000001);
1710            const INACTIVE_PRESSED_OVERLAY_COLOR: Color = Color::new(0xFF000002);
1711            const HOVER_OVERLAY_COLOR: Color = Color::new(0xFF000003);
1712            const HOVER_COLOR: Color = Color::new(0xFF000005);
1713            const SPLASH_RADIUS: f64 = 24.0;
1714            let overlay = <dyn WidgetStateProperty<Option<Color>>>::resolve_with(|states| {
1715                if states.contains(&WidgetState::Pressed) {
1716                    if states.contains(&WidgetState::Selected) {
1717                        return Some(ACTIVE_PRESSED_OVERLAY_COLOR);
1718                    }
1719                    return Some(INACTIVE_PRESSED_OVERLAY_COLOR);
1720                }
1721                if states.contains(&WidgetState::Hovered) {
1722                    return Some(HOVER_OVERLAY_COLOR);
1723                }
1724                None
1725            });
1726            let frame = |tester: &mut WidgetTester, active: bool, use_overlay: bool| {
1727                let overlay = Rc::clone(&overlay);
1728                pump_in_material(tester, m2, move |_app| {
1729                    let mut tile = CheckboxListTile::new(Some(active), ignore())
1730                        .fill_color(Rc::new(waft_widgets::WidgetStatePropertyAll::new(Some(
1731                            FILL_COLOR,
1732                        )))
1733                            as WidgetStatePropertyRef<Option<Color>>)
1734                        .hover_color(HOVER_COLOR)
1735                        .splash_radius(SPLASH_RADIUS);
1736                    if use_overlay {
1737                        tile = tile.overlay_color(overlay);
1738                    }
1739                    tile.into_widget()
1740                });
1741            };
1742            let any_circle = || waft_rendering::testing::PaintCall::circle(None);
1743            let reaction = FILL_COLOR.with_alpha(crate::constants::K_RADIAL_REACTION_ALPHA);
1744            let mut presses = Vec::new();
1745            for (pointer, (active, use_overlay, expected)) in [
1746                (false, false, reaction),
1747                (true, false, reaction),
1748                (false, true, INACTIVE_PRESSED_OVERLAY_COLOR),
1749                (true, true, ACTIVE_PRESSED_OVERLAY_COLOR),
1750            ]
1751            .into_iter()
1752            .enumerate()
1753            {
1754                frame(tester, active, use_overlay);
1755                presses.push(press(tester, pointer as i64 + 2));
1756                tester.pump_and_settle();
1757                assert_paints(
1758                    tester,
1759                    checkbox_material(tester),
1760                    &[any_circle(), circle(expected).radius(SPLASH_RADIUS)],
1761                );
1762            }
1763
1764            // Start hovering
1765            tester.pump_widget(Container::new().into_widget());
1766            frame(tester, false, true);
1767            tester.pump_and_settle();
1768            let gesture = hover(tester);
1769            tester.pump_and_settle();
1770            assert_paints(
1771                tester,
1772                checkbox_material(tester),
1773                &[circle(HOVER_OVERLAY_COLOR).radius(SPLASH_RADIUS)],
1774            );
1775
1776            // Finish gestures to release resources.
1777            for pressed in &presses {
1778                tester.up(pressed);
1779            }
1780            tester.pump_and_settle();
1781            tester.send(&gesture, PointerChange::Remove);
1782        });
1783    }
1784
1785    #[test]
1786    fn material3_checkbox_list_tile_respects_overlay_color_in_active_pressed_hovered_states() {
1787        test_widgets(|tester| {
1788            tester.set_highlight_strategy(FocusHighlightStrategy::AlwaysTraditional);
1789            const FILL_COLOR: Color = Color::new(0xFF000000);
1790            const ACTIVE_PRESSED_OVERLAY_COLOR: Color = Color::new(0xFF000001);
1791            const INACTIVE_PRESSED_OVERLAY_COLOR: Color = Color::new(0xFF000002);
1792            const HOVER_OVERLAY_COLOR: Color = Color::new(0xFF000003);
1793            const HOVER_COLOR: Color = Color::new(0xFF000005);
1794            const SPLASH_RADIUS: f64 = 24.0;
1795            let overlay = <dyn WidgetStateProperty<Option<Color>>>::resolve_with(|states| {
1796                if states.contains(&WidgetState::Pressed) {
1797                    if states.contains(&WidgetState::Selected) {
1798                        return Some(ACTIVE_PRESSED_OVERLAY_COLOR);
1799                    }
1800                    return Some(INACTIVE_PRESSED_OVERLAY_COLOR);
1801                }
1802                if states.contains(&WidgetState::Hovered) {
1803                    return Some(HOVER_OVERLAY_COLOR);
1804                }
1805                None
1806            });
1807            let frame = |tester: &mut WidgetTester, active: bool, use_overlay: bool| {
1808                let overlay = Rc::clone(&overlay);
1809                pump_in_material(tester, m3, move |_app| {
1810                    let mut tile = CheckboxListTile::new(Some(active), ignore())
1811                        .fill_color(Rc::new(waft_widgets::WidgetStatePropertyAll::new(Some(
1812                            FILL_COLOR,
1813                        )))
1814                            as WidgetStatePropertyRef<Option<Color>>)
1815                        .hover_color(HOVER_COLOR)
1816                        .splash_radius(SPLASH_RADIUS);
1817                    if use_overlay {
1818                        tile = tile.overlay_color(overlay);
1819                    }
1820                    tile.into_widget()
1821                });
1822            };
1823            let reaction = FILL_COLOR.with_alpha(crate::constants::K_RADIAL_REACTION_ALPHA);
1824            let mut presses = Vec::new();
1825            for (pointer, (active, use_overlay, expected)) in [
1826                (false, false, reaction),
1827                (true, false, reaction),
1828                (false, true, INACTIVE_PRESSED_OVERLAY_COLOR),
1829                (true, true, ACTIVE_PRESSED_OVERLAY_COLOR),
1830            ]
1831            .into_iter()
1832            .enumerate()
1833            {
1834                frame(tester, active, use_overlay);
1835                presses.push(press(tester, pointer as i64 + 2));
1836                tester.pump_and_settle();
1837                assert_paints(
1838                    tester,
1839                    &[PaintCall::Circle {
1840                        x: None,
1841                        y: None,
1842                        radius: Some(SPLASH_RADIUS),
1843                        color: Some(expected),
1844                        style: None,
1845                    }],
1846                );
1847            }
1848
1849            // Start hovering
1850            tester.pump_widget(Container::new().into_widget());
1851            frame(tester, false, true);
1852            tester.pump_and_settle();
1853            let gesture = hover(tester);
1854            tester.pump_and_settle();
1855            assert_paints(
1856                tester,
1857                &[PaintCall::Circle {
1858                    x: None,
1859                    y: None,
1860                    radius: Some(SPLASH_RADIUS),
1861                    color: Some(HOVER_OVERLAY_COLOR),
1862                    style: None,
1863                }],
1864            );
1865
1866            // Finish gestures to release resources.
1867            for pressed in &presses {
1868                tester.up(pressed);
1869            }
1870            tester.pump_and_settle();
1871            tester.send(&gesture, PointerChange::Remove);
1872        });
1873    }
1874
1875    #[test]
1876    fn checkbox_list_tile_respects_splash_radius() {
1877        test_widgets(|tester| {
1878            tester.set_highlight_strategy(FocusHighlightStrategy::AlwaysTraditional);
1879            const SPLASH_RADIUS: f64 = 30.0;
1880            let orange = Colors::ORANGE.shade500();
1881            pump_wrapped(tester, |_app| {
1882                CheckboxListTile::new(Some(false), ignore())
1883                    .hover_color(orange)
1884                    .splash_radius(SPLASH_RADIUS)
1885                    .into_widget()
1886            });
1887            tester.pump_and_settle();
1888            let gesture = hover(tester);
1889            tester.pump_and_settle();
1890            assert_paints(
1891                tester,
1892                &[PaintCall::Circle {
1893                    x: None,
1894                    y: None,
1895                    radius: Some(SPLASH_RADIUS),
1896                    color: Some(orange),
1897                    style: None,
1898                }],
1899            );
1900            tester.send(&gesture, PointerChange::Remove);
1901        });
1902    }
1903
1904    #[test]
1905    fn checkbox_list_tile_respects_material_tap_target_size() {
1906        test_widgets(|tester| {
1907            pump_wrapped(tester, |_app| {
1908                CheckboxListTile::new(Some(true), ignore()).into_widget()
1909            });
1910            // default test
1911            assert_eq!(checkbox_size(tester), Size::new(40.0, 40.0));
1912
1913            pump_wrapped(tester, |_app| {
1914                CheckboxListTile::new(Some(true), ignore())
1915                    .material_tap_target_size(MaterialTapTargetSize::Padded)
1916                    .into_widget()
1917            });
1918            assert_eq!(checkbox_size(tester), Size::new(48.0, 48.0));
1919        });
1920    }
1921
1922    #[test]
1923    fn material3_checkbox_list_tile_respects_is_error() {
1924        test_widgets(|tester| {
1925            let colors = m3(&tester.cell.borrow()).color_scheme.clone();
1926            tester.set_highlight_strategy(FocusHighlightStrategy::AlwaysTraditional);
1927            let value = Rc::new(Cell::new(Some(true)));
1928            let host = stateful_tile(&value, |tile| tile.is_error(true));
1929
1930            // Default color
1931            tester.pump_widget(Container::new().into_widget());
1932            pump_in_material(tester, m3, |_app| Center::new().child(host).into_widget());
1933            tester.pump_and_settle();
1934            assert_paints(
1935                tester,
1936                &[
1937                    PaintCall::rrect(Some(colors.error())),
1938                    PaintCall::path(Some(colors.on_error())),
1939                ],
1940            );
1941
1942            // Start hovering
1943            let gesture = hover(tester);
1944            tester.pump_and_settle();
1945            assert_paints(
1946                tester,
1947                &[
1948                    PaintCall::circle(Some(colors.error().with_opacity(0.08))),
1949                    PaintCall::rrect(Some(colors.error())),
1950                ],
1951            );
1952            tester.send(&gesture, PointerChange::Remove);
1953        });
1954    }
1955
1956    #[test]
1957    fn checkbox_list_tile_adaptive_shows_the_correct_checkbox_platform_widget() {
1958        test_widgets(|tester| {
1959            for (platform, cupertino) in [
1960                (TargetPlatform::IOS, 1),
1961                (TargetPlatform::MacOS, 1),
1962                (TargetPlatform::Android, 0),
1963                (TargetPlatform::Fuchsia, 0),
1964                (TargetPlatform::Linux, 0),
1965                (TargetPlatform::Windows, 0),
1966            ] {
1967                pump_in_material(
1968                    tester,
1969                    move |app| ThemeData::builder().platform(platform).build(app),
1970                    |_app| {
1971                        Center::new()
1972                            .child(CheckboxListTile::adaptive(Some(false), ignore()))
1973                            .into_widget()
1974                    },
1975                );
1976                tester.pump_and_settle();
1977                assert_eq!(
1978                    find::by_type::<waft_cupertino::CupertinoCheckbox>()
1979                        .evaluate(tester)
1980                        .len(),
1981                    cupertino,
1982                    "{platform:?}"
1983                );
1984            }
1985        });
1986    }
1987
1988    #[test]
1989    fn checkbox_list_tile_respects_enable_feedback() {
1990        test_widgets(|tester| {
1991            for enable_feedback in [false, true] {
1992                pump_wrapped(tester, |_app| {
1993                    Center::new()
1994                        .child(
1995                            CheckboxListTile::new(Some(false), ignore())
1996                                .enable_feedback(enable_feedback),
1997                        )
1998                        .into_widget()
1999                });
2000                assert_eq!(ink_well_enable_feedback(tester), enable_feedback);
2001            }
2002        });
2003    }
2004
2005    /// Dart's "control widget should not request focus on traversal" case for two tiles
2006    /// `make(title)`.
2007    pub(crate) fn check_control_is_skipped_by_traversal(
2008        tester: &mut WidgetTester,
2009        make: impl Fn(WidgetRef) -> WidgetRef,
2010    ) {
2011        let first_child_key = GlobalKey::new();
2012        let second_child_key = GlobalKey::new();
2013        let first = make(
2014            Text::new("Hey")
2015                .key(first_child_key.clone().into())
2016                .into_widget(),
2017        );
2018        let second = make(
2019            Text::new("There")
2020                .key(second_child_key.clone().into())
2021                .into_widget(),
2022        );
2023        pump_in_material(tester, m3, |_app| {
2024            Column::new().children([first, second]).into_widget()
2025        });
2026        tester.pump();
2027        let first_node = focus_of(tester, &first_child_key);
2028        first_node.request_focus(&mut tester.cell.borrow_mut(), None);
2029        tester.pump();
2030        assert!(has_primary_focus(tester, first_node));
2031        first_node.next_focus(&mut tester.cell.borrow_mut());
2032        tester.pump();
2033        assert!(!has_primary_focus(
2034            tester,
2035            focus_of(tester, &first_child_key)
2036        ));
2037        assert!(has_primary_focus(
2038            tester,
2039            focus_of(tester, &second_child_key)
2040        ));
2041    }
2042
2043    #[test]
2044    fn checkbox_list_tile_control_widget_should_not_request_focus_on_traversal() {
2045        test_widgets(|tester| {
2046            check_control_is_skipped_by_traversal(tester, |title| {
2047                CheckboxListTile::new(Some(true), ignore())
2048                    .title(title)
2049                    .into_widget()
2050            });
2051        });
2052    }
2053
2054    /// Dart's "uses ListTileTheme controlAffinity" case: where the control `C` of
2055    /// `make()` sits under each affinity.
2056    pub(crate) fn control_top_left_under<C: 'static>(
2057        tester: &mut WidgetTester,
2058        make: impl Fn() -> WidgetRef,
2059        control_affinity: ListTileControlAffinity,
2060    ) -> Offset {
2061        let tile = make();
2062        pump_in_material(tester, m3, |_app| {
2063            ListTileTheme::new(tile)
2064                .data(ListTileThemeData::new().control_affinity(control_affinity))
2065                .into_widget()
2066        });
2067        rect_of::<C>(tester, 0).top_left()
2068    }
2069
2070    #[test]
2071    fn checkbox_list_tile_uses_list_tile_theme_control_affinity() {
2072        test_widgets(|tester| {
2073            let make = || CheckboxListTile::new(Some(false), ignore()).into_widget();
2074            for (control_affinity, expected) in [
2075                (ListTileControlAffinity::Trailing, Offset::new(736.0, 8.0)),
2076                (ListTileControlAffinity::Leading, Offset::new(16.0, 8.0)),
2077                (ListTileControlAffinity::Platform, Offset::new(736.0, 8.0)),
2078            ] {
2079                assert_eq!(
2080                    control_top_left_under::<Checkbox>(tester, make, control_affinity),
2081                    expected
2082                );
2083            }
2084        });
2085    }
2086
2087    #[test]
2088    fn checkbox_list_tile_renders_with_default_scale() {
2089        test_widgets(|tester| {
2090            pump_in_material(tester, m3, |_app| {
2091                CheckboxListTile::new(Some(false), None).into_widget()
2092            });
2093            let checkbox = nth::<Checkbox>(tester, 0);
2094            let app = tester.cell.borrow();
2095            assert!(!tester.ancestors(checkbox).into_iter().any(|ancestor| {
2096                waft_widgets::downcast_widget::<Transform>(&**ancestor.widget(&app)).is_some()
2097            }));
2098        });
2099    }
2100
2101    #[test]
2102    fn checkbox_list_tile_respects_checkbox_scale_factor() {
2103        test_widgets(|tester| {
2104            const SCALE: f64 = 1.5;
2105            pump_in_material(tester, m3, |_app| {
2106                CheckboxListTile::new(Some(false), None)
2107                    .checkbox_scale_factor(SCALE)
2108                    .into_widget()
2109            });
2110            let transform = tester.element(
2111                find::ancestor(
2112                    find::by_type::<Checkbox>().at(0),
2113                    find::by_type::<Transform>(),
2114                )
2115                .first(),
2116            );
2117            let matrix = tester.widget(transform, |transform: &Transform| transform.transform);
2118            assert_eq!(matrix, Matrix4::scale(SCALE as f32, SCALE as f32));
2119        });
2120    }
2121
2122    fn three_line_tile(is_three_line: Option<bool>, subtitle: &str) -> WidgetRef {
2123        let mut tile = CheckboxListTile::new(Some(false), None)
2124            .title(Text::new("A"))
2125            .subtitle(Text::new(subtitle));
2126        tile.is_three_line = is_three_line;
2127        tile.into_widget()
2128    }
2129
2130    fn adaptive_three_line_tile(is_three_line: Option<bool>, subtitle: &str) -> WidgetRef {
2131        let mut tile = CheckboxListTile::adaptive(Some(false), None)
2132            .title(Text::new("A"))
2133            .subtitle(Text::new(subtitle));
2134        tile.is_three_line = is_three_line;
2135        tile.into_widget()
2136    }
2137
2138    #[test]
2139    fn checkbox_list_tile_is_three_line() {
2140        test_widgets(|tester| {
2141            for (frame, three_line) in IS_THREE_LINE_FRAMES {
2142                assert_eq!(
2143                    is_three_line_rects::<Checkbox, CheckboxListTile>(
2144                        tester,
2145                        TargetPlatform::Android,
2146                        frame,
2147                        three_line_tile
2148                    ),
2149                    expected_three_line_rects(
2150                        three_line,
2151                        800.0 - 40.0 - 24.0,
2152                        Size::new(40.0, 40.0),
2153                        [130.0, 300.0 + 16.0]
2154                    ),
2155                    "{frame:?}"
2156                );
2157            }
2158        });
2159    }
2160
2161    #[test]
2162    fn checkbox_list_tile_adaptive_is_three_line() {
2163        test_widgets(|tester| {
2164            for (frame, three_line) in IS_THREE_LINE_FRAMES {
2165                assert_eq!(
2166                    is_three_line_rects::<Checkbox, CheckboxListTile>(
2167                        tester,
2168                        TargetPlatform::IOS,
2169                        frame,
2170                        adaptive_three_line_tile
2171                    ),
2172                    expected_three_line_rects(
2173                        three_line,
2174                        800.0 - 44.0 - 24.0,
2175                        Size::new(44.0, 44.0),
2176                        [128.0, 300.0 + 14.0]
2177                    ),
2178                    "{frame:?}"
2179                );
2180            }
2181        });
2182    }
2183
2184    fn title_alignment_tile(
2185        title_alignment: Option<ListTileTitleAlignment>,
2186        secondary: WidgetRef,
2187        with_subtitle: bool,
2188    ) -> WidgetRef {
2189        let mut tile = CheckboxListTile::new(Some(true), ignore())
2190            .control_affinity(ListTileControlAffinity::Leading)
2191            .title(SizedBox::new().width(20.0).height(50.0))
2192            .secondary(secondary);
2193        if with_subtitle {
2194            tile = tile.subtitle(SizedBox::new().width(20.0).height(50.0));
2195        }
2196        tile.title_alignment = title_alignment;
2197        tile.into_widget()
2198    }
2199
2200    #[test]
2201    fn title_alignment_position_with_title_widget() {
2202        test_widgets(|tester| {
2203            check_title_alignment::<Checkbox>(tester, title_alignment_tile, false);
2204        });
2205    }
2206
2207    #[test]
2208    fn title_alignment_position_with_title_and_subtitle_widgets() {
2209        test_widgets(|tester| {
2210            check_title_alignment::<Checkbox>(tester, title_alignment_tile, true);
2211        });
2212    }
2213
2214    /// Dart's "does not crash at zero area" case for `tile`.
2215    pub(crate) fn check_zero_area<W: 'static>(tester: &mut WidgetTester, tile: WidgetRef) {
2216        pump_app(tester, m3, |app| {
2217            let theme = m3(app);
2218            Center::new()
2219                .child(
2220                    SizedBox::shrink()
2221                        .child(Scaffold::new().body(bare(theme, Material::new().child(tile)))),
2222                )
2223                .into_widget()
2224        });
2225        assert_eq!(rect_of::<W>(tester, 0).size(), Size::ZERO);
2226    }
2227
2228    #[test]
2229    fn checkbox_list_tile_does_not_crash_at_zero_area() {
2230        test_widgets(|tester| {
2231            check_zero_area::<CheckboxListTile>(
2232                tester,
2233                CheckboxListTile::new(Some(true), ignore())
2234                    .title(Text::new("X"))
2235                    .into_widget(),
2236            );
2237        });
2238    }
2239
2240    fn leading_title_tile() -> CheckboxListTile {
2241        CheckboxListTile::new(Some(true), ignore())
2242            .control_affinity(ListTileControlAffinity::Leading)
2243            .title(Text::new("title"))
2244    }
2245
2246    /// Dart's "horizontalTitleGap = 0.0" case for `make(gap)`, whose title starts (LTR) and
2247    /// ends (RTL) at the given edges.
2248    pub(crate) fn check_horizontal_title_gap_0(
2249        tester: &mut WidgetTester,
2250        [ltr_edge, rtl_edge]: [f64; 2],
2251        make: impl Fn(Option<f64>) -> WidgetRef,
2252    ) {
2253        for (text_direction, edge) in [
2254            (TextDirection::Ltr, ltr_edge),
2255            (TextDirection::Rtl, rtl_edge),
2256        ] {
2257            for (theme_gap, widget_gap) in THEME_AND_WIDGET_FRAMES {
2258                let mut data = ListTileThemeData::new();
2259                data.horizontal_title_gap = theme_gap;
2260                spacing_frame(tester, m3, text_direction, data, make(widget_gap));
2261                assert_eq!(list_tile_size(tester), Size::new(800.0, 56.0));
2262                assert_eq!(title_edge(tester, text_direction), edge);
2263            }
2264        }
2265    }
2266
2267    #[test]
2268    fn checkbox_list_tile_horizontal_title_gap_0() {
2269        test_widgets(|tester| {
2270            check_horizontal_title_gap_0(tester, [56.0, 744.0], |gap| {
2271                let mut tile = leading_title_tile();
2272                tile.horizontal_title_gap = gap;
2273                tile.into_widget()
2274            });
2275        });
2276    }
2277
2278    /// Dart's "horizontalTitleGap = (default) && ListTile minLeadingWidth = (default)" case.
2279    pub(crate) fn check_default_horizontal_title_gap(
2280        tester: &mut WidgetTester,
2281        [ltr_edge, rtl_edge]: [f64; 2],
2282        make: impl Fn() -> WidgetRef,
2283    ) {
2284        // horizontalTitleGap: ListTileDefaultValue.horizontalTitleGap (16.0)
2285        for (text_direction, edge) in [
2286            (TextDirection::Ltr, ltr_edge),
2287            (TextDirection::Rtl, rtl_edge),
2288        ] {
2289            spacing_frame(tester, m3, text_direction, ListTileThemeData::new(), make());
2290            assert_eq!(list_tile_size(tester), Size::new(800.0, 56.0));
2291            assert_eq!(title_edge(tester, text_direction), edge);
2292        }
2293    }
2294
2295    #[test]
2296    fn checkbox_list_tile_default_horizontal_title_gap_and_min_leading_width() {
2297        test_widgets(|tester| {
2298            check_default_horizontal_title_gap(tester, [72.0, 728.0], || {
2299                leading_title_tile().into_widget()
2300            });
2301        });
2302    }
2303
2304    /// Dart's "horizontalTitleGap with visualDensity" case: twice the same frame, the title
2305    /// starting at `edge`.
2306    pub(crate) fn check_horizontal_title_gap_with_visual_density(
2307        tester: &mut WidgetTester,
2308        edge: f64,
2309        make: impl Fn() -> WidgetRef,
2310    ) {
2311        spacing_frame(
2312            tester,
2313            m3,
2314            TextDirection::Ltr,
2315            ListTileThemeData::new(),
2316            make(),
2317        );
2318        assert_eq!(list_tile_size(tester), Size::new(800.0, 56.0));
2319        assert_eq!(title_edge(tester, TextDirection::Ltr), edge);
2320
2321        // Pump another frame of the same widget to ensure the underlying render
2322        // object did not cache the original horizontalTitleGap calculation based on the
2323        // visualDensity
2324        let tile = make();
2325        pump_app(tester, m3, |_app| {
2326            Directionality::new(
2327                TextDirection::Ltr,
2328                Material::new().child(
2329                    ListTileTheme::new(
2330                        Container::new()
2331                            .alignment(AlignmentGeometry::TOP_LEFT)
2332                            .child(tile),
2333                    )
2334                    .data(ListTileThemeData::new()),
2335                ),
2336            )
2337            .into_widget()
2338        });
2339        assert_eq!(list_tile_size(tester), Size::new(800.0, 56.0));
2340        assert_eq!(title_edge(tester, TextDirection::Ltr), edge);
2341    }
2342
2343    #[test]
2344    fn checkbox_list_tile_horizontal_title_gap_with_visual_density() {
2345        test_widgets(|tester| {
2346            check_horizontal_title_gap_with_visual_density(tester, 58.0, || {
2347                leading_title_tile()
2348                    .visual_density(VisualDensity::new(VisualDensity::MINIMUM_DENSITY, 0.0))
2349                    .horizontal_title_gap(10.0)
2350                    .into_widget()
2351            });
2352        });
2353    }
2354
2355    /// Dart's "minVerticalPadding = 80.0" case under `theme`, with the tile `height` it
2356    /// expects.
2357    pub(crate) fn check_min_vertical_padding_80(
2358        tester: &mut WidgetTester,
2359        theme: fn(&App) -> ThemeData,
2360        height: f64,
2361        make: impl Fn(Option<f64>) -> WidgetRef,
2362    ) {
2363        for text_direction in [TextDirection::Ltr, TextDirection::Rtl] {
2364            for (theme_padding, widget_padding) in theme_and_widget_frames(80.0) {
2365                let mut data = ListTileThemeData::new();
2366                data.min_vertical_padding = theme_padding;
2367                spacing_frame(tester, theme, text_direction, data, make(widget_padding));
2368                assert_eq!(list_tile_size(tester), Size::new(800.0, height));
2369            }
2370        }
2371    }
2372
2373    fn min_vertical_padding_tile(padding: Option<f64>) -> WidgetRef {
2374        let mut tile = CheckboxListTile::new(Some(true), ignore()).title(Text::new("title"));
2375        tile.min_vertical_padding = padding;
2376        tile.into_widget()
2377    }
2378
2379    #[test]
2380    fn checkbox_list_tile_min_vertical_padding_80_material_3() {
2381        // 80 + 80 + 24(Title) = 184
2382        test_widgets(|tester| {
2383            check_min_vertical_padding_80(tester, m3, 184.0, min_vertical_padding_tile);
2384        });
2385    }
2386
2387    #[test]
2388    fn checkbox_list_tile_min_vertical_padding_80_material_2() {
2389        // 80 + 80 + 16(Title) = 176
2390        test_widgets(|tester| {
2391            check_min_vertical_padding_80(tester, m2, 176.0, min_vertical_padding_tile);
2392        });
2393    }
2394
2395    /// Dart's "minLeadingWidth = 60.0" case.
2396    pub(crate) fn check_min_leading_width_60(
2397        tester: &mut WidgetTester,
2398        make: impl Fn(Option<f64>) -> WidgetRef,
2399    ) {
2400        // 92.0 = 16.0(Default contentPadding) + 16.0(Default horizontalTitleGap) + 60.0
2401        // 708.0 = 800.0 - (16.0(Default contentPadding) + 16.0(Default horizontalTitleGap) + 60.0)
2402        for (text_direction, edge) in [(TextDirection::Ltr, 92.0), (TextDirection::Rtl, 708.0)] {
2403            for (theme_width, widget_width) in theme_and_widget_frames(60.0) {
2404                let mut data = ListTileThemeData::new();
2405                data.min_leading_width = theme_width;
2406                spacing_frame(tester, m3, text_direction, data, make(widget_width));
2407                assert_eq!(list_tile_size(tester), Size::new(800.0, 56.0));
2408                assert_eq!(title_edge(tester, text_direction), edge);
2409            }
2410        }
2411    }
2412
2413    #[test]
2414    fn checkbox_list_tile_min_leading_width_60() {
2415        test_widgets(|tester| {
2416            check_min_leading_width_60(tester, |width| {
2417                let mut tile = leading_title_tile();
2418                tile.min_leading_width = width;
2419                tile.into_widget()
2420            });
2421        });
2422    }
2423
2424    /// Dart's "minTileHeight" case.
2425    pub(crate) fn check_min_tile_height(
2426        tester: &mut WidgetTester,
2427        make: impl Fn(Option<f64>) -> WidgetRef,
2428    ) {
2429        for (min_tile_height, height) in [(None, 56.0), (Some(30.0), 30.0), (Some(60.0), 60.0)] {
2430            spacing_frame(
2431                tester,
2432                m3,
2433                TextDirection::Ltr,
2434                ListTileThemeData::new(),
2435                make(min_tile_height),
2436            );
2437            assert_eq!(list_tile_size(tester), Size::new(800.0, height));
2438        }
2439    }
2440
2441    #[test]
2442    fn checkbox_list_tile_min_tile_height() {
2443        test_widgets(|tester| {
2444            check_min_tile_height(tester, |min_tile_height| {
2445                let mut tile = CheckboxListTile::new(Some(true), ignore());
2446                tile.min_tile_height = min_tile_height;
2447                tile.into_widget()
2448            });
2449        });
2450    }
2451
2452    /// Dart's `assert(tristate || value != null)`.
2453    #[test]
2454    #[should_panic(expected = "self.tristate || self.value.is_some()")]
2455    fn a_checkbox_list_tile_that_is_not_tristate_without_a_value_panics_when_made_a_widget() {
2456        CheckboxListTile::new(None, ignore()).into_widget();
2457    }
2458}