Skip to main content

waft_material/
expansion_tile_theme.rs

1//! Flutter counterpart: material_ui's `expansion_tile_theme.dart`.
2
3use waft_animation::AnimationStyle;
4use waft_embedder::{Clip, Color};
5use waft_foundation::{App, DiagnosticsProperty};
6use waft_painting::{AlignmentGeometry, ColorProperty, EdgeInsetsGeometry, ShapeBorderRef};
7use waft_widgets::{BuildContext, InheritedTheme, InheritedWidget, IntoWidget, KeyRef, WidgetRef};
8
9use crate::theme::Theme;
10
11/// Used with [`ExpansionTileTheme`] to define default property values for
12/// descendant `ExpansionTile` widgets.
13///
14/// Descendant widgets obtain the current [`ExpansionTileThemeData`] object
15/// using [`ExpansionTileTheme::of`]. Instances of [`ExpansionTileThemeData`] can
16/// be customized with [`ExpansionTileThemeData::copy_with`].
17///
18/// A [`ExpansionTileThemeData`] is often specified as part of the
19/// overall `Theme` with `ThemeData::expansion_tile_theme`.
20///
21/// All [`ExpansionTileThemeData`] properties are `None` by default.
22/// When a theme property is `None`, the `ExpansionTile`  will provide its own
23/// default based on the overall `Theme`'s text theme and
24/// color scheme. See the individual `ExpansionTile` properties for details.
25///
26/// See also:
27///
28///  * `ThemeData`, which describes the overall theme information for the
29///    application.
30///  * [`ExpansionTileTheme`] which overrides the default [`ExpansionTileTheme`]
31///    of its `ExpansionTile` descendants.
32///  * `ThemeData::text_theme`, text with a color that contrasts with the card
33///    and canvas colors.
34///  * `ThemeData::color_scheme`, the thirteen colors that most Material widget
35///    default colors are based on.
36#[derive(Clone, Debug, Default)]
37pub struct ExpansionTileThemeData {
38    /// Overrides the default value of `ExpansionTile::background_color`.
39    pub background_color: Option<Color>,
40
41    /// Overrides the default value of `ExpansionTile::collapsed_background_color`.
42    pub collapsed_background_color: Option<Color>,
43
44    /// Overrides the default value of `ExpansionTile::tile_padding`.
45    pub tile_padding: Option<EdgeInsetsGeometry>,
46
47    /// Overrides the default value of `ExpansionTile::expanded_alignment`.
48    pub expanded_alignment: Option<AlignmentGeometry>,
49
50    /// Overrides the default value of `ExpansionTile::children_padding`.
51    pub children_padding: Option<EdgeInsetsGeometry>,
52
53    /// Overrides the default value of `ExpansionTile::icon_color`.
54    pub icon_color: Option<Color>,
55
56    /// Overrides the default value of `ExpansionTile::collapsed_icon_color`.
57    pub collapsed_icon_color: Option<Color>,
58
59    /// Overrides the default value of `ExpansionTile::text_color`.
60    pub text_color: Option<Color>,
61
62    /// Overrides the default value of `ExpansionTile::collapsed_text_color`.
63    pub collapsed_text_color: Option<Color>,
64
65    /// Overrides the default value of `ExpansionTile::shape`.
66    pub shape: Option<ShapeBorderRef>,
67
68    /// Overrides the default value of `ExpansionTile::collapsed_shape`.
69    pub collapsed_shape: Option<ShapeBorderRef>,
70
71    /// Overrides the default value of `ExpansionTile::clip_behavior`.
72    pub clip_behavior: Option<Clip>,
73
74    /// Overrides the default value of `ExpansionTile::expansion_animation_style`.
75    pub expansion_animation_style: Option<AnimationStyle>,
76}
77
78crate::theme_data_getters::theme_data_getters! {
79    /// Dart's getters of `ExpansionTileThemeData`: the theme data answers with its fields, and a defaults
80    /// subclass (Dart's `_...Defaults...(context)`) computes the ones it overrides when they
81    /// are read.
82    pub trait ExpansionTileThemeDataGetters for ExpansionTileThemeData, fields: expansion_tile_theme_data {
83        background_color: Option<Color>,
84        collapsed_background_color: Option<Color>,
85        tile_padding: Option<EdgeInsetsGeometry>,
86        expanded_alignment: Option<AlignmentGeometry>,
87        children_padding: Option<EdgeInsetsGeometry>,
88        icon_color: Option<Color>,
89        collapsed_icon_color: Option<Color>,
90        text_color: Option<Color>,
91        collapsed_text_color: Option<Color>,
92        shape: Option<ShapeBorderRef>,
93        collapsed_shape: Option<ShapeBorderRef>,
94        clip_behavior: Option<Clip>,
95        expansion_animation_style: Option<AnimationStyle>,
96    }
97}
98
99impl ExpansionTileThemeData {
100    /// Creates a [`ExpansionTileThemeData`]; Dart's optional named arguments are the fluent
101    /// setters.
102    pub fn new() -> ExpansionTileThemeData {
103        ExpansionTileThemeData::default()
104    }
105
106    /// Dart `ExpansionTileThemeData(backgroundColor:)`.
107    pub fn background_color(mut self, background_color: Color) -> ExpansionTileThemeData {
108        self.background_color = Some(background_color);
109        self
110    }
111
112    /// Dart `ExpansionTileThemeData(collapsedBackgroundColor:)`.
113    pub fn collapsed_background_color(
114        mut self,
115        collapsed_background_color: Color,
116    ) -> ExpansionTileThemeData {
117        self.collapsed_background_color = Some(collapsed_background_color);
118        self
119    }
120
121    /// Dart `ExpansionTileThemeData(tilePadding:)`.
122    pub fn tile_padding(
123        mut self,
124        tile_padding: impl Into<EdgeInsetsGeometry>,
125    ) -> ExpansionTileThemeData {
126        self.tile_padding = Some(tile_padding.into());
127        self
128    }
129
130    /// Dart `ExpansionTileThemeData(expandedAlignment:)`.
131    pub fn expanded_alignment(
132        mut self,
133        expanded_alignment: impl Into<AlignmentGeometry>,
134    ) -> ExpansionTileThemeData {
135        self.expanded_alignment = Some(expanded_alignment.into());
136        self
137    }
138
139    /// Dart `ExpansionTileThemeData(childrenPadding:)`.
140    pub fn children_padding(
141        mut self,
142        children_padding: impl Into<EdgeInsetsGeometry>,
143    ) -> ExpansionTileThemeData {
144        self.children_padding = Some(children_padding.into());
145        self
146    }
147
148    /// Dart `ExpansionTileThemeData(iconColor:)`.
149    pub fn icon_color(mut self, icon_color: Color) -> ExpansionTileThemeData {
150        self.icon_color = Some(icon_color);
151        self
152    }
153
154    /// Dart `ExpansionTileThemeData(collapsedIconColor:)`.
155    pub fn collapsed_icon_color(mut self, collapsed_icon_color: Color) -> ExpansionTileThemeData {
156        self.collapsed_icon_color = Some(collapsed_icon_color);
157        self
158    }
159
160    /// Dart `ExpansionTileThemeData(textColor:)`.
161    pub fn text_color(mut self, text_color: Color) -> ExpansionTileThemeData {
162        self.text_color = Some(text_color);
163        self
164    }
165
166    /// Dart `ExpansionTileThemeData(collapsedTextColor:)`.
167    pub fn collapsed_text_color(mut self, collapsed_text_color: Color) -> ExpansionTileThemeData {
168        self.collapsed_text_color = Some(collapsed_text_color);
169        self
170    }
171
172    /// Dart `ExpansionTileThemeData(shape:)`.
173    pub fn shape(mut self, shape: impl Into<ShapeBorderRef>) -> ExpansionTileThemeData {
174        self.shape = Some(shape.into());
175        self
176    }
177
178    /// Dart `ExpansionTileThemeData(collapsedShape:)`.
179    pub fn collapsed_shape(
180        mut self,
181        collapsed_shape: impl Into<ShapeBorderRef>,
182    ) -> ExpansionTileThemeData {
183        self.collapsed_shape = Some(collapsed_shape.into());
184        self
185    }
186
187    /// Dart `ExpansionTileThemeData(clipBehavior:)`.
188    pub fn clip_behavior(mut self, clip_behavior: Clip) -> ExpansionTileThemeData {
189        self.clip_behavior = Some(clip_behavior);
190        self
191    }
192
193    /// Dart `ExpansionTileThemeData(expansionAnimationStyle:)`.
194    pub fn expansion_animation_style(
195        mut self,
196        expansion_animation_style: AnimationStyle,
197    ) -> ExpansionTileThemeData {
198        self.expansion_animation_style = Some(expansion_animation_style);
199        self
200    }
201
202    /// Creates a copy of this object with the given fields replaced with the
203    /// new values.
204    ///
205    /// Dart's named arguments are the fluent setters on the copy
206    /// (`data.copy_with().icon_color(c)`).
207    pub fn copy_with(&self) -> ExpansionTileThemeData {
208        self.clone()
209    }
210
211    /// Linearly interpolate between ExpansionTileThemeData objects.
212    pub fn lerp(
213        a: Option<&ExpansionTileThemeData>,
214        b: Option<&ExpansionTileThemeData>,
215        t: f64,
216    ) -> Option<ExpansionTileThemeData> {
217        match (a, b) {
218            (None, None) => return None,
219            (Some(a), Some(b)) if std::ptr::eq(a, b) => return Some(a.clone()),
220            _ => {}
221        }
222        Some(ExpansionTileThemeData {
223            background_color: Color::lerp(
224                a.and_then(|a| a.background_color),
225                b.and_then(|b| b.background_color),
226                t,
227            ),
228            collapsed_background_color: Color::lerp(
229                a.and_then(|a| a.collapsed_background_color),
230                b.and_then(|b| b.collapsed_background_color),
231                t,
232            ),
233            tile_padding: EdgeInsetsGeometry::lerp(
234                a.and_then(|a| a.tile_padding),
235                b.and_then(|b| b.tile_padding),
236                t,
237            ),
238            expanded_alignment: AlignmentGeometry::lerp(
239                a.and_then(|a| a.expanded_alignment),
240                b.and_then(|b| b.expanded_alignment),
241                t,
242            ),
243            children_padding: EdgeInsetsGeometry::lerp(
244                a.and_then(|a| a.children_padding),
245                b.and_then(|b| b.children_padding),
246                t,
247            ),
248            icon_color: Color::lerp(
249                a.and_then(|a| a.icon_color),
250                b.and_then(|b| b.icon_color),
251                t,
252            ),
253            collapsed_icon_color: Color::lerp(
254                a.and_then(|a| a.collapsed_icon_color),
255                b.and_then(|b| b.collapsed_icon_color),
256                t,
257            ),
258            text_color: Color::lerp(
259                a.and_then(|a| a.text_color),
260                b.and_then(|b| b.text_color),
261                t,
262            ),
263            collapsed_text_color: Color::lerp(
264                a.and_then(|a| a.collapsed_text_color),
265                b.and_then(|b| b.collapsed_text_color),
266                t,
267            ),
268            shape: ShapeBorderRef::lerp(
269                a.and_then(|a| a.shape.as_ref()),
270                b.and_then(|b| b.shape.as_ref()),
271                t,
272            ),
273            collapsed_shape: ShapeBorderRef::lerp(
274                a.and_then(|a| a.collapsed_shape.as_ref()),
275                b.and_then(|b| b.collapsed_shape.as_ref()),
276                t,
277            ),
278            clip_behavior: pick(a, b, t, |theme| theme.clip_behavior),
279            expansion_animation_style: pick(a, b, t, |theme| {
280                theme.expansion_animation_style.clone()
281            }),
282        })
283    }
284}
285
286/// Dart's `t < 0.5 ? a?.field : b?.field`.
287fn pick<T>(
288    a: Option<&ExpansionTileThemeData>,
289    b: Option<&ExpansionTileThemeData>,
290    t: f64,
291    field: impl Fn(&ExpansionTileThemeData) -> Option<T>,
292) -> Option<T> {
293    if t < 0.5 {
294        a.and_then(&field)
295    } else {
296        b.and_then(&field)
297    }
298}
299
300impl PartialEq for ExpansionTileThemeData {
301    fn eq(&self, other: &ExpansionTileThemeData) -> bool {
302        if std::ptr::eq(self, other) {
303            return true;
304        }
305        other.background_color == self.background_color
306            && other.collapsed_background_color == self.collapsed_background_color
307            && other.tile_padding == self.tile_padding
308            && other.expanded_alignment == self.expanded_alignment
309            && other.children_padding == self.children_padding
310            && other.icon_color == self.icon_color
311            && other.collapsed_icon_color == self.collapsed_icon_color
312            && other.text_color == self.text_color
313            && other.collapsed_text_color == self.collapsed_text_color
314            && other.shape == self.shape
315            && other.collapsed_shape == self.collapsed_shape
316            && other.clip_behavior == self.clip_behavior
317            && other.expansion_animation_style == self.expansion_animation_style
318    }
319}
320
321/// Overrides the default [`ExpansionTileTheme`] of its `ExpansionTile` descendants.
322///
323/// See also:
324///
325///  * [`ExpansionTileThemeData`], which is used to configure this theme.
326///  * `ThemeData::expansion_tile_theme`, which can be used to override the default
327///    [`ExpansionTileTheme`] for `ExpansionTile`s below the overall `Theme`.
328#[derive(Debug)]
329pub struct ExpansionTileTheme {
330    pub key: Option<KeyRef>,
331    /// Specifies color, alignment, and text style values for
332    /// descendant `ExpansionTile` widgets.
333    pub data: ExpansionTileThemeData,
334    pub child: WidgetRef,
335}
336
337impl ExpansionTileTheme {
338    /// Applies the given theme [`data`](Self::data) to [`child`](Self::child).
339    #[cfg_attr(debug_assertions, track_caller)]
340    pub fn new<K>(data: ExpansionTileThemeData, child: impl IntoWidget<K>) -> ExpansionTileTheme {
341        ExpansionTileTheme {
342            key: None,
343            data,
344            child: child.into_widget(),
345        }
346    }
347
348    /// Dart `ExpansionTileTheme(key:)`.
349    pub fn key(mut self, key: KeyRef) -> ExpansionTileTheme {
350        self.key = Some(key);
351        self
352    }
353
354    /// Retrieves the [`ExpansionTileThemeData`] from the closest ancestor [`ExpansionTileTheme`].
355    ///
356    /// If there is no enclosing [`ExpansionTileTheme`] widget, then
357    /// `ThemeData::expansion_tile_theme` is used.
358    ///
359    /// Typical usage is as follows:
360    ///
361    /// ```text
362    /// let theme = ExpansionTileTheme::of(app, context);
363    /// ```
364    pub fn of(app: &mut App, context: BuildContext) -> ExpansionTileThemeData {
365        match context.depend_on_inherited_widget_of_exact_type::<ExpansionTileTheme>(app) {
366            Some(inherited_theme) => inherited_theme.data.clone(),
367            None => Theme::of(app, context).expansion_tile_theme.clone(),
368        }
369    }
370}
371
372impl InheritedTheme for ExpansionTileTheme {
373    fn wrap(&self, _app: &mut App, _context: BuildContext, child: WidgetRef) -> WidgetRef {
374        ExpansionTileTheme::new(self.data.clone(), child).into_widget()
375    }
376}
377
378impl InheritedWidget for ExpansionTileTheme {
379    fn key(&self) -> Option<&KeyRef> {
380        self.key.as_ref()
381    }
382
383    fn child(&self) -> &WidgetRef {
384        &self.child
385    }
386
387    fn update_should_notify(&self, old_widget: &ExpansionTileTheme) -> bool {
388        self.data != old_widget.data
389    }
390
391    fn as_inherited_theme(&self) -> Option<&dyn InheritedTheme> {
392        Some(self)
393    }
394}
395
396/// Dart's `AnimationStyle.toString`: its `debugFillProperties` properties, at the info level.
397fn expansion_animation_style(value: &AnimationStyle) -> String {
398    let mut properties = Vec::new();
399    if let Some(curve) = &value.curve {
400        properties.push(format!("curve: {curve:?}"));
401    }
402    if let Some(duration) = &value.duration {
403        properties.push(format!(
404            "duration: {}",
405            waft_embedder::SignedDuration::from(*duration)
406        ));
407    }
408    if let Some(curve) = &value.reverse_curve {
409        properties.push(format!("reverseCurve: {curve:?}"));
410    }
411    if let Some(duration) = &value.reverse_duration {
412        properties.push(format!(
413            "reverseDuration: {}",
414            waft_embedder::SignedDuration::from(*duration)
415        ));
416    }
417    let identity = waft_foundation::describe_identity(
418        "AnimationStyle",
419        value as *const AnimationStyle as *const () as usize as u64,
420    );
421    if properties.is_empty() {
422        identity
423    } else {
424        format!("{identity}({})", properties.join(", "))
425    }
426}
427
428impl waft_foundation::Diagnosticable for ExpansionTileThemeData {
429    fn debug_fill_properties(&self, properties: &mut waft_foundation::DiagnosticPropertiesBuilder) {
430        properties
431            .add(ColorProperty::new("backgroundColor", self.background_color).default_value(None));
432        properties.add(
433            ColorProperty::new("collapsedBackgroundColor", self.collapsed_background_color)
434                .default_value(None),
435        );
436        properties.add(
437            DiagnosticsProperty::<EdgeInsetsGeometry>::new("tilePadding", self.tile_padding)
438                .default_value(None),
439        );
440        properties.add(
441            DiagnosticsProperty::<AlignmentGeometry>::new(
442                "expandedAlignment",
443                self.expanded_alignment,
444            )
445            .default_value(None),
446        );
447        properties.add(
448            DiagnosticsProperty::<EdgeInsetsGeometry>::new(
449                "childrenPadding",
450                self.children_padding,
451            )
452            .default_value(None),
453        );
454        properties.add(ColorProperty::new("iconColor", self.icon_color).default_value(None));
455        properties.add(
456            ColorProperty::new("collapsedIconColor", self.collapsed_icon_color).default_value(None),
457        );
458        properties.add(ColorProperty::new("textColor", self.text_color).default_value(None));
459        properties.add(
460            ColorProperty::new("collapsedTextColor", self.collapsed_text_color).default_value(None),
461        );
462        properties.add(
463            DiagnosticsProperty::<ShapeBorderRef>::new("shape", self.shape.clone())
464                .default_value(None),
465        );
466        properties.add(
467            DiagnosticsProperty::<ShapeBorderRef>::new(
468                "collapsedShape",
469                self.collapsed_shape.clone(),
470            )
471            .default_value(None),
472        );
473        properties.add(
474            DiagnosticsProperty::<waft_foundation::DartEnum<Clip>>::new(
475                "clipBehavior",
476                self.clip_behavior.map(waft_foundation::DartEnum),
477            )
478            .default_value(None),
479        );
480        properties.add(
481            DiagnosticsProperty::<String>::new(
482                "expansionAnimationStyle",
483                self.expansion_animation_style
484                    .as_ref()
485                    .map(expansion_animation_style),
486            )
487            .default_value(None),
488        );
489    }
490}
491
492impl std::fmt::Display for ExpansionTileThemeData {
493    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
494        f.write_str(&waft_foundation::Diagnosticable::to_string(self))
495    }
496}
497
498#[cfg(test)]
499mod tests {
500    use waft_animation::Curves;
501    use waft_embedder::Color;
502    use waft_painting::{Alignment, Border, BorderSide, EdgeInsets};
503    use waft_widgets::{Center, GlobalKey, Text};
504
505    use waft_widgets::testing::{WidgetTester, find, test_widgets};
506
507    use super::*;
508    use crate::colors::Colors;
509    use crate::expansion_tile::ExpansionTile;
510    use crate::expansion_tile::tests::{
511        animation_style_case, expand_more_rect, last_padding_rect, list_tile_rect, probe, pump_app,
512        sized, test_icon, test_text, tile_material,
513    };
514    use crate::material::Material;
515    use crate::theme_data::ThemeData;
516
517    /// "ExpansionTileThemeData copyWith, ==, hashCode basics".
518    #[test]
519    fn expansion_tile_theme_data_copy_with_equality_basics() {
520        assert_eq!(
521            ExpansionTileThemeData::new(),
522            ExpansionTileThemeData::new().copy_with()
523        );
524    }
525
526    /// "ExpansionTileThemeData lerp special cases".
527    #[test]
528    fn expansion_tile_theme_data_lerp_special_cases() {
529        assert_eq!(ExpansionTileThemeData::lerp(None, None, 0.0), None);
530        let data = ExpansionTileThemeData::new();
531        // Dart's `identical`: the value comes back as it was.
532        assert_eq!(
533            ExpansionTileThemeData::lerp(Some(&data), Some(&data), 0.5),
534            Some(data.clone())
535        );
536    }
537
538    /// "ExpansionTileThemeData defaults".
539    #[test]
540    fn expansion_tile_theme_data_defaults() {
541        let theme = ExpansionTileThemeData::new();
542        assert_eq!(theme.background_color, None);
543        assert_eq!(theme.collapsed_background_color, None);
544        assert_eq!(theme.tile_padding, None);
545        assert_eq!(theme.expanded_alignment, None);
546        assert_eq!(theme.children_padding, None);
547        assert_eq!(theme.icon_color, None);
548        assert_eq!(theme.collapsed_icon_color, None);
549        assert_eq!(theme.text_color, None);
550        assert_eq!(theme.collapsed_text_color, None);
551        assert!(theme.shape.is_none());
552        assert!(theme.collapsed_shape.is_none());
553        assert_eq!(theme.clip_behavior, None);
554        assert_eq!(theme.expansion_animation_style, None);
555    }
556
557    /// `Border(top: BorderSide(color: color), bottom: BorderSide(color: color))`.
558    fn vertical_border(color: Color) -> Border {
559        let side = BorderSide {
560            color,
561            ..BorderSide::default()
562        };
563        Border {
564            top: side,
565            bottom: side,
566            ..Border::default()
567        }
568    }
569
570    fn icon_color() -> Color {
571        Colors::GREEN.primary()
572    }
573
574    fn collapsed_icon_color() -> Color {
575        Colors::BLUE.primary()
576    }
577
578    const TEXT_COLOR: Color = Colors::BLACK;
579    const COLLAPSED_TEXT_COLOR: Color = Colors::WHITE;
580
581    /// The theme both "ExpansionTileTheme" cases put in `ThemeData.expansionTileTheme`.
582    fn full_theme(clip_behavior: Clip) -> ExpansionTileThemeData {
583        ExpansionTileThemeData::new()
584            .background_color(Colors::ORANGE.primary())
585            .collapsed_background_color(Colors::RED.primary())
586            .tile_padding(EdgeInsets::from_ltrb(8.0, 12.0, 4.0, 10.0))
587            .expanded_alignment(Alignment::CENTER_RIGHT)
588            .children_padding(EdgeInsets::all(20.0))
589            .icon_color(icon_color())
590            .collapsed_icon_color(collapsed_icon_color())
591            .text_color(TEXT_COLOR)
592            .collapsed_text_color(COLLAPSED_TEXT_COLOR)
593            .shape(vertical_border(Colors::RED.primary()))
594            .collapsed_shape(vertical_border(Colors::GREEN.primary()))
595            .clip_behavior(clip_behavior)
596    }
597
598    /// The title and trailing positions both "ExpansionTileTheme" cases check after the
599    /// theme's tile padding is applied.
600    fn assert_tile_padding(tester: &WidgetTester, title: &str) {
601        let title_rect = tester.get_rect(find::text(title));
602        let trailing_rect = expand_more_rect(tester);
603        let list_tile_rect = list_tile_rect(tester);
604        let taller_widget = if title_rect.height() > trailing_rect.height() {
605            title_rect
606        } else {
607            trailing_rect
608        };
609
610        // Check the positions of title and trailing Widgets, after padding is applied.
611        assert_eq!(list_tile_rect.left, title_rect.left - 8.0);
612        assert_eq!(list_tile_rect.right, trailing_rect.right + 4.0);
613
614        // Calculate the remaining height of ListTile from the default height.
615        let remaining_height = 56.0 - taller_widget.height();
616        assert_eq!(
617            list_tile_rect.top,
618            taller_widget.top - remaining_height / 2.0 - 12.0
619        );
620        assert_eq!(
621            list_tile_rect.bottom,
622            taller_widget.bottom + remaining_height / 2.0 + 10.0
623        );
624    }
625
626    fn boxed(shape: Border) -> Option<ShapeBorderRef> {
627        Some(ShapeBorderRef::new(shape))
628    }
629
630    /// "ExpansionTileTheme - collapsed".
631    #[test]
632    fn expansion_tile_theme_collapsed() {
633        test_widgets(|tester| {
634            let icon = probe();
635            let text = probe();
636            let clip_behavior = Clip::AntiAlias;
637
638            pump_app(
639                tester,
640                |app| {
641                    ThemeData::builder()
642                        .expansion_tile_theme(full_theme(clip_behavior))
643                        .build(app)
644                },
645                Material::new().child(
646                    Center::new().child(
647                        ExpansionTile::new(test_text("Collapsed Tile", &text))
648                            .trailing(test_icon(&icon))
649                            .children([Text::new("Tile 1").into_widget()]),
650                    ),
651                ),
652            );
653
654            // When a custom shape is provided, ExpansionTile will use the
655            // Material widget to draw the shape and background color
656            // instead of a Container.
657            let (shape, color, material_clip_behavior) = tile_material(tester);
658
659            // ExpansionTile should have Clip.antiAlias as clipBehavior.
660            assert_eq!(material_clip_behavior, clip_behavior);
661
662            // Check the tile's collapsed background color when collapsedBackgroundColor is
663            // applied.
664            assert_eq!(color, Some(Colors::RED.primary()));
665
666            assert_tile_padding(tester, "Collapsed Tile");
667
668            // Check the collapsed icon color when iconColor is applied.
669            assert_eq!(icon.get(), Some(collapsed_icon_color()));
670            // Check the collapsed text color when textColor is applied.
671            assert_eq!(text.get(), Some(COLLAPSED_TEXT_COLOR));
672            // Check the collapsed ShapeBorder when shape is applied.
673            assert_eq!(shape, boxed(vertical_border(Colors::GREEN.primary())));
674        });
675    }
676
677    /// "ExpansionTileTheme - expanded".
678    #[test]
679    fn expansion_tile_theme_expanded() {
680        test_widgets(|tester| {
681            let icon = probe();
682            let text = probe();
683            let clip_behavior = Clip::None;
684
685            pump_app(
686                tester,
687                |app| {
688                    ThemeData::builder()
689                        .expansion_tile_theme(full_theme(clip_behavior))
690                        .build(app)
691                },
692                Material::new().child(
693                    Center::new().child(
694                        ExpansionTile::new(test_text("Expanded Tile", &text))
695                            .initially_expanded(true)
696                            .trailing(test_icon(&icon))
697                            .children([Text::new("Tile 1").into_widget()]),
698                    ),
699                ),
700            );
701
702            // When a custom shape is provided, ExpansionTile will use the
703            // Material widget to draw the shape and background color
704            // instead of a Container.
705            let (shape, color, material_clip_behavior) = tile_material(tester);
706            // Check the tile's background color when backgroundColor is applied.
707            assert_eq!(color, Some(Colors::ORANGE.primary()));
708
709            assert_tile_padding(tester, "Expanded Tile");
710
711            // Check the expanded icon color when iconColor is applied.
712            assert_eq!(icon.get(), Some(icon_color()));
713            // Check the expanded text color when textColor is applied.
714            assert_eq!(text.get(), Some(TEXT_COLOR));
715            // Check the expanded ShapeBorder when shape is applied.
716            assert_eq!(shape, boxed(vertical_border(Colors::RED.primary())));
717            // Check the clipBehavior when shape is applied.
718            assert_eq!(material_clip_behavior, clip_behavior);
719
720            // Check the child position when expandedAlignment is applied.
721            let child = find::text("Tile 1").evaluate(tester);
722            assert_eq!(child.len(), 1, "one \"Tile 1\"");
723            let child_rect = tester.get_rect(child[0]);
724            assert_eq!(child_rect.right, 800.0 - 20.0);
725            assert_eq!(child_rect.left, 800.0 - child_rect.width() - 20.0);
726
727            // Check the child padding when childrenPadding is applied.
728            let padding_rect = last_padding_rect(tester);
729            assert_eq!(child_rect.top, padding_rect.top + 20.0);
730            assert_eq!(child_rect.left, padding_rect.left + 20.0);
731            assert_eq!(child_rect.right, padding_rect.right - 20.0);
732            assert_eq!(child_rect.bottom, padding_rect.bottom - 20.0);
733        });
734    }
735
736    /// "Override ExpansionTile animation using ExpansionTileThemeData.AnimationStyle".
737    #[test]
738    fn override_expansion_tile_animation_using_expansion_tile_theme_data_animation_style() {
739        test_widgets(|tester| {
740            animation_style_case(
741                tester,
742                |tester, key: &GlobalKey, animation_style| {
743                    let mut expansion_tile_theme = ExpansionTileThemeData::new();
744                    expansion_tile_theme.expansion_animation_style = animation_style;
745                    pump_app(
746                        tester,
747                        |app| {
748                            ThemeData::builder()
749                                .expansion_tile_theme(expansion_tile_theme)
750                                .build(app)
751                        },
752                        Material::new().child(
753                            Center::new().child(
754                                ExpansionTile::new(test_text("title", &probe()))
755                                    .key(key.clone().into())
756                                    .children([sized(100.0, 100.0)]),
757                            ),
758                        ),
759                    );
760                },
761                false,
762            );
763        });
764    }
765    // Flutter's "Default ExpansionTileThemeData debugFillProperties".
766    #[test]
767    fn a_expansion_tile_theme_data_describes_nothing_by_default() {
768        assert_eq!(
769            waft_widgets::testing::describe_properties(|properties| {
770                waft_foundation::Diagnosticable::debug_fill_properties(
771                    &ExpansionTileThemeData::new(),
772                    properties,
773                )
774            }),
775            Vec::<String>::new()
776        );
777    }
778
779    // expansion_tile_theme_test.dart 'ExpansionTileThemeData implements debugFillProperties'.
780    #[test]
781    fn an_assigned_expansion_tile_theme_describes_every_property() {
782        let theme = ExpansionTileThemeData::new()
783            .background_color(Color::new(0xff000000))
784            .collapsed_background_color(Color::new(0xff6f83fc))
785            .tile_padding(EdgeInsetsGeometry::all(20.0))
786            .expanded_alignment(AlignmentGeometry::BOTTOM_CENTER)
787            .children_padding(EdgeInsetsGeometry::all(10.0))
788            .icon_color(Color::new(0xffa7c61c))
789            .collapsed_icon_color(Color::new(0xffdd0b1f))
790            .text_color(Color::new(0xffffffff))
791            .collapsed_text_color(Color::new(0xff522bab))
792            .shape(Border::default())
793            .collapsed_shape(Border::default())
794            .clip_behavior(Clip::AntiAlias)
795            .expansion_animation_style(AnimationStyle::new(
796                Some(Curves::ease_in_out()),
797                None,
798                None,
799                None,
800            ));
801        let description = waft_widgets::testing::describe_properties(|properties| {
802            waft_foundation::Diagnosticable::debug_fill_properties(&theme, properties)
803        });
804        let description: Vec<String> = description
805            .iter()
806            .map(|line| waft_rendering::testing::ignoring_hash_codes(line))
807            .collect();
808        assert_eq!(
809            description,
810            [
811                format!("backgroundColor: {}", Color::new(0xff000000)),
812                format!(
813                    "collapsedBackgroundColor: {}",
814                    Color::new(0xff6f83fc)
815                ),
816                "tilePadding: EdgeInsets.all(20.0)".to_string(),
817                "expandedAlignment: Alignment.bottomCenter".to_string(),
818                "childrenPadding: EdgeInsets.all(10.0)".to_string(),
819                format!("iconColor: {}", Color::new(0xffa7c61c)),
820                format!("collapsedIconColor: {}", Color::new(0xffdd0b1f)),
821                format!("textColor: {}", Color::new(0xffffffff)),
822                format!("collapsedTextColor: {}", Color::new(0xff522bab)),
823                "shape: Border.all(BorderSide(width: 0.0, style: none))".to_string(),
824                "collapsedShape: Border.all(BorderSide(width: 0.0, style: none))".to_string(),
825                "clipBehavior: Clip.antiAlias".to_string(),
826                "expansionAnimationStyle: AnimationStyle#00000(curve: Cubic(0.42, 0.00, 0.58, 1.00))"
827                    .to_string(),
828            ]
829        );
830    }
831}