Skip to main content

waft_material/
tab_bar_theme.rs

1//! Flutter counterpart: material_ui's `tab_bar_theme.dart`.
2
3use waft_embedder::Color;
4use waft_foundation::{App, DiagnosticsProperty};
5use waft_painting::{
6    AnyColor, BorderRadius, DecorationRef, EdgeInsetsGeometry, TextScaler, TextStyle,
7};
8use waft_services::MouseCursorRef;
9use waft_widgets::{
10    BuildContext, InheritedTheme, InheritedWidget, IntoWidget, KeyRef, SizedBox, WidgetRef,
11    WidgetStateProperty, WidgetStatePropertyRef,
12};
13
14use crate::ink_well::InteractiveInkFeatureFactoryRef;
15use crate::tabs::{TabAlignment, TabBarIndicatorSize, TabIndicatorAnimation};
16use crate::theme::Theme;
17
18/// Defines default property values for descendant `TabBar` widgets.
19///
20/// Descendant widgets obtain the current [`TabBarThemeData`] object using
21/// [`TabBarTheme::of`]. Instances of [`TabBarThemeData`] can be customized
22/// with [`TabBarThemeData::copy_with`].
23///
24/// Typically a [`TabBarThemeData`] is specified as part of the overall `Theme`
25/// with `ThemeData::tab_bar_theme`.
26///
27/// Dart's `TabBarTheme` constructor takes either the properties or a [`data`](Self::data);
28/// here the properties are the `with_*` setters and [`with_data`](Self::with_data) the other,
29/// and each setter that breaks Dart's constructor assert (a `data` together with any property)
30/// fails in a debug build. The getters are methods, as Dart's, hence the `with_` prefix.
31///
32/// See also:
33///
34///  * [`TabBarThemeData`], which describes the actual configuration of a tab
35///    bar theme.
36#[derive(Clone, Debug)]
37pub struct TabBarTheme {
38    pub key: Option<KeyRef>,
39    data: Option<TabBarThemeData>,
40    indicator: Option<DecorationRef>,
41    indicator_color: Option<Color>,
42    indicator_size: Option<TabBarIndicatorSize>,
43    divider_color: Option<Color>,
44    divider_height: Option<f64>,
45    label_color: Option<AnyColor>,
46    label_padding: Option<EdgeInsetsGeometry>,
47    label_style: Option<TextStyle>,
48    unselected_label_color: Option<Color>,
49    unselected_label_style: Option<TextStyle>,
50    overlay_color: Option<WidgetStatePropertyRef<Option<Color>>>,
51    splash_factory: Option<InteractiveInkFeatureFactoryRef>,
52    mouse_cursor: Option<WidgetStatePropertyRef<Option<MouseCursorRef>>>,
53    tab_alignment: Option<TabAlignment>,
54    text_scaler: Option<TextScaler>,
55    indicator_animation: Option<TabIndicatorAnimation>,
56    child: WidgetRef,
57}
58
59impl TabBarTheme {
60    /// Creates a tab bar theme that can be used with `ThemeData::tab_bar_theme`.
61    pub fn new() -> TabBarTheme {
62        TabBarTheme {
63            key: None,
64            data: None,
65            indicator: None,
66            indicator_color: None,
67            indicator_size: None,
68            divider_color: None,
69            divider_height: None,
70            label_color: None,
71            label_padding: None,
72            label_style: None,
73            unselected_label_color: None,
74            unselected_label_style: None,
75            overlay_color: None,
76            splash_factory: None,
77            mouse_cursor: None,
78            tab_alignment: None,
79            text_scaler: None,
80            indicator_animation: None,
81            child: SizedBox::new().into_widget(),
82        }
83    }
84
85    /// Dart `TabBarTheme(key:)`.
86    pub fn key(mut self, key: KeyRef) -> TabBarTheme {
87        self.key = Some(key);
88        self
89    }
90
91    /// Dart `TabBarTheme(child:)`; the default is an empty `SizedBox`.
92    #[cfg_attr(debug_assertions, track_caller)]
93    pub fn child<K>(mut self, child: impl IntoWidget<K>) -> TabBarTheme {
94        self.child = child.into_widget();
95        self
96    }
97
98    /// Dart `TabBarTheme(data:)`.
99    pub fn with_data(mut self, data: TabBarThemeData) -> TabBarTheme {
100        debug_assert!(self.has_no_property());
101        self.data = Some(data);
102        self
103    }
104
105    /// Dart `TabBarTheme(indicator:)`.
106    pub fn with_indicator(mut self, indicator: impl Into<DecorationRef>) -> TabBarTheme {
107        debug_assert!(self.data.is_none());
108        self.indicator = Some(indicator.into());
109        self
110    }
111
112    /// Dart `TabBarTheme(indicatorColor:)`.
113    pub fn with_indicator_color(mut self, indicator_color: Color) -> TabBarTheme {
114        debug_assert!(self.data.is_none());
115        self.indicator_color = Some(indicator_color);
116        self
117    }
118
119    /// Dart `TabBarTheme(indicatorSize:)`.
120    pub fn with_indicator_size(mut self, indicator_size: TabBarIndicatorSize) -> TabBarTheme {
121        debug_assert!(self.data.is_none());
122        self.indicator_size = Some(indicator_size);
123        self
124    }
125
126    /// Dart `TabBarTheme(dividerColor:)`.
127    pub fn with_divider_color(mut self, divider_color: Color) -> TabBarTheme {
128        debug_assert!(self.data.is_none());
129        self.divider_color = Some(divider_color);
130        self
131    }
132
133    /// Dart `TabBarTheme(dividerHeight:)`.
134    pub fn with_divider_height(mut self, divider_height: f64) -> TabBarTheme {
135        debug_assert!(self.data.is_none());
136        self.divider_height = Some(divider_height);
137        self
138    }
139
140    /// Dart `TabBarTheme(labelColor:)`.
141    pub fn with_label_color(mut self, label_color: impl Into<AnyColor>) -> TabBarTheme {
142        debug_assert!(self.data.is_none());
143        self.label_color = Some(label_color.into());
144        self
145    }
146
147    /// Dart `TabBarTheme(labelPadding:)`.
148    pub fn with_label_padding(
149        mut self,
150        label_padding: impl Into<EdgeInsetsGeometry>,
151    ) -> TabBarTheme {
152        debug_assert!(self.data.is_none());
153        self.label_padding = Some(label_padding.into());
154        self
155    }
156
157    /// Dart `TabBarTheme(labelStyle:)`.
158    pub fn with_label_style(mut self, label_style: TextStyle) -> TabBarTheme {
159        debug_assert!(self.data.is_none());
160        self.label_style = Some(label_style);
161        self
162    }
163
164    /// Dart `TabBarTheme(unselectedLabelColor:)`.
165    pub fn with_unselected_label_color(mut self, unselected_label_color: Color) -> TabBarTheme {
166        debug_assert!(self.data.is_none());
167        self.unselected_label_color = Some(unselected_label_color);
168        self
169    }
170
171    /// Dart `TabBarTheme(unselectedLabelStyle:)`.
172    pub fn with_unselected_label_style(mut self, unselected_label_style: TextStyle) -> TabBarTheme {
173        debug_assert!(self.data.is_none());
174        self.unselected_label_style = Some(unselected_label_style);
175        self
176    }
177
178    /// Dart `TabBarTheme(overlayColor:)`.
179    pub fn with_overlay_color(
180        mut self,
181        overlay_color: WidgetStatePropertyRef<Option<Color>>,
182    ) -> TabBarTheme {
183        debug_assert!(self.data.is_none());
184        self.overlay_color = Some(overlay_color);
185        self
186    }
187
188    /// Dart `TabBarTheme(splashFactory:)`.
189    pub fn with_splash_factory(
190        mut self,
191        splash_factory: InteractiveInkFeatureFactoryRef,
192    ) -> TabBarTheme {
193        debug_assert!(self.data.is_none());
194        self.splash_factory = Some(splash_factory);
195        self
196    }
197
198    /// Dart `TabBarTheme(mouseCursor:)`.
199    pub fn with_mouse_cursor(
200        mut self,
201        mouse_cursor: WidgetStatePropertyRef<Option<MouseCursorRef>>,
202    ) -> TabBarTheme {
203        debug_assert!(self.data.is_none());
204        self.mouse_cursor = Some(mouse_cursor);
205        self
206    }
207
208    /// Dart `TabBarTheme(tabAlignment:)`.
209    pub fn with_tab_alignment(mut self, tab_alignment: TabAlignment) -> TabBarTheme {
210        debug_assert!(self.data.is_none());
211        self.tab_alignment = Some(tab_alignment);
212        self
213    }
214
215    /// Dart `TabBarTheme(textScaler:)`.
216    pub fn with_text_scaler(mut self, text_scaler: TextScaler) -> TabBarTheme {
217        debug_assert!(self.data.is_none());
218        self.text_scaler = Some(text_scaler);
219        self
220    }
221
222    /// Dart `TabBarTheme(indicatorAnimation:)`.
223    pub fn with_indicator_animation(
224        mut self,
225        indicator_animation: TabIndicatorAnimation,
226    ) -> TabBarTheme {
227        debug_assert!(self.data.is_none());
228        self.indicator_animation = Some(indicator_animation);
229        self
230    }
231
232    /// Overrides the default value for `TabBar::indicator`.
233    ///
234    /// This property is obsolete and will be deprecated in a future release:
235    /// please use the [`TabBarThemeData::indicator`] property in [`data`](Self::data) instead.
236    pub fn indicator(&self) -> Option<&DecorationRef> {
237        match &self.data {
238            Some(data) => data.indicator.as_ref(),
239            None => self.indicator.as_ref(),
240        }
241    }
242
243    /// Overrides the default value for `TabBar::indicator_color`.
244    ///
245    /// This property is obsolete and will be deprecated in a future release:
246    /// please use the [`TabBarThemeData::indicator_color`] property in [`data`](Self::data) instead.
247    pub fn indicator_color(&self) -> Option<Color> {
248        match &self.data {
249            Some(data) => data.indicator_color,
250            None => self.indicator_color,
251        }
252    }
253
254    /// Overrides the default value for `TabBar::indicator_size`.
255    ///
256    /// This property is obsolete and will be deprecated in a future release:
257    /// please use the [`TabBarThemeData::indicator_size`] property in [`data`](Self::data) instead.
258    pub fn indicator_size(&self) -> Option<TabBarIndicatorSize> {
259        match &self.data {
260            Some(data) => data.indicator_size,
261            None => self.indicator_size,
262        }
263    }
264
265    /// Overrides the default value for `TabBar::divider_color`.
266    ///
267    /// This property is obsolete and will be deprecated in a future release:
268    /// please use the [`TabBarThemeData::divider_color`] property in [`data`](Self::data) instead.
269    pub fn divider_color(&self) -> Option<Color> {
270        match &self.data {
271            Some(data) => data.divider_color,
272            None => self.divider_color,
273        }
274    }
275
276    /// Overrides the default value for `TabBar::divider_height`.
277    ///
278    /// This property is obsolete and will be deprecated in a future release:
279    /// please use the [`TabBarThemeData::divider_height`] property in [`data`](Self::data) instead.
280    pub fn divider_height(&self) -> Option<f64> {
281        match &self.data {
282            Some(data) => data.divider_height,
283            None => self.divider_height,
284        }
285    }
286
287    /// Overrides the default value for `TabBar::label_color`.
288    ///
289    /// This property is obsolete and will be deprecated in a future release:
290    /// please use the [`TabBarThemeData::label_color`] property in [`data`](Self::data) instead.
291    pub fn label_color(&self) -> Option<&AnyColor> {
292        match &self.data {
293            Some(data) => data.label_color.as_ref(),
294            None => self.label_color.as_ref(),
295        }
296    }
297
298    /// Overrides the default value for `TabBar::label_padding`.
299    ///
300    /// This property is obsolete and will be deprecated in a future release:
301    /// please use the [`TabBarThemeData::label_padding`] property in [`data`](Self::data) instead.
302    pub fn label_padding(&self) -> Option<EdgeInsetsGeometry> {
303        match &self.data {
304            Some(data) => data.label_padding,
305            None => self.label_padding,
306        }
307    }
308
309    /// Overrides the default value for `TabBar::label_style`.
310    ///
311    /// This property is obsolete and will be deprecated in a future release:
312    /// please use the [`TabBarThemeData::label_style`] property in [`data`](Self::data) instead.
313    pub fn label_style(&self) -> Option<&TextStyle> {
314        match &self.data {
315            Some(data) => data.label_style.as_ref(),
316            None => self.label_style.as_ref(),
317        }
318    }
319
320    /// Overrides the default value for `TabBar::unselected_label_color`.
321    ///
322    /// This property is obsolete and will be deprecated in a future release:
323    /// please use the [`TabBarThemeData::unselected_label_color`] property in [`data`](Self::data) instead.
324    pub fn unselected_label_color(&self) -> Option<Color> {
325        match &self.data {
326            Some(data) => data.unselected_label_color,
327            None => self.unselected_label_color,
328        }
329    }
330
331    /// Overrides the default value for `TabBar::unselected_label_style`.
332    ///
333    /// This property is obsolete and will be deprecated in a future release:
334    /// please use the [`TabBarThemeData::unselected_label_style`] property in [`data`](Self::data) instead.
335    pub fn unselected_label_style(&self) -> Option<&TextStyle> {
336        match &self.data {
337            Some(data) => data.unselected_label_style.as_ref(),
338            None => self.unselected_label_style.as_ref(),
339        }
340    }
341
342    /// Overrides the default value for `TabBar::overlay_color`.
343    ///
344    /// This property is obsolete and will be deprecated in a future release:
345    /// please use the [`TabBarThemeData::overlay_color`] property in [`data`](Self::data) instead.
346    pub fn overlay_color(&self) -> Option<WidgetStatePropertyRef<Option<Color>>> {
347        match &self.data {
348            Some(data) => data.overlay_color.clone(),
349            None => self.overlay_color.clone(),
350        }
351    }
352
353    /// Overrides the default value for `TabBar::splash_factory`.
354    ///
355    /// This property is obsolete and will be deprecated in a future release:
356    /// please use the [`TabBarThemeData::splash_factory`] property in [`data`](Self::data) instead.
357    pub fn splash_factory(&self) -> Option<InteractiveInkFeatureFactoryRef> {
358        match &self.data {
359            Some(data) => data.splash_factory.clone(),
360            None => self.splash_factory.clone(),
361        }
362    }
363
364    /// Overrides the default value of `TabBar::mouse_cursor`.
365    ///
366    /// This property is obsolete and will be deprecated in a future release:
367    /// please use the [`TabBarThemeData::mouse_cursor`] property in [`data`](Self::data) instead.
368    pub fn mouse_cursor(&self) -> Option<WidgetStatePropertyRef<Option<MouseCursorRef>>> {
369        match &self.data {
370            Some(data) => data.mouse_cursor.clone(),
371            None => self.mouse_cursor.clone(),
372        }
373    }
374
375    /// Overrides the default value for `TabBar::tab_alignment`.
376    ///
377    /// This property is obsolete and will be deprecated in a future release:
378    /// please use the [`TabBarThemeData::tab_alignment`] property in [`data`](Self::data) instead.
379    pub fn tab_alignment(&self) -> Option<TabAlignment> {
380        match &self.data {
381            Some(data) => data.tab_alignment,
382            None => self.tab_alignment,
383        }
384    }
385
386    /// Overrides the default value for `TabBar::text_scaler`.
387    ///
388    /// This property is obsolete and will be deprecated in a future release:
389    /// please use the [`TabBarThemeData::text_scaler`] property in [`data`](Self::data) instead.
390    pub fn text_scaler(&self) -> Option<&TextScaler> {
391        match &self.data {
392            Some(data) => data.text_scaler.as_ref(),
393            None => self.text_scaler.as_ref(),
394        }
395    }
396
397    /// Overrides the default value for `TabBar::indicator_animation`.
398    ///
399    /// This property is obsolete and will be deprecated in a future release:
400    /// please use the [`TabBarThemeData::indicator_animation`] property in [`data`](Self::data) instead.
401    pub fn indicator_animation(&self) -> Option<TabIndicatorAnimation> {
402        match &self.data {
403            Some(data) => data.indicator_animation,
404            None => self.indicator_animation,
405        }
406    }
407
408    /// The properties used for all descendant `TabBar` widgets.
409    pub fn data(&self) -> TabBarThemeData {
410        self.data.clone().unwrap_or_else(|| TabBarThemeData {
411            indicator: self.indicator.clone(),
412            indicator_color: self.indicator_color,
413            indicator_size: self.indicator_size,
414            divider_color: self.divider_color,
415            divider_height: self.divider_height,
416            label_color: self.label_color.clone(),
417            label_padding: self.label_padding,
418            label_style: self.label_style.clone(),
419            unselected_label_color: self.unselected_label_color,
420            unselected_label_style: self.unselected_label_style.clone(),
421            overlay_color: self.overlay_color.clone(),
422            splash_factory: self.splash_factory.clone(),
423            mouse_cursor: self.mouse_cursor.clone(),
424            tab_alignment: self.tab_alignment,
425            text_scaler: self.text_scaler.clone(),
426            indicator_animation: self.indicator_animation,
427            splash_border_radius: None,
428        })
429    }
430
431    /// Creates a copy of this object but with the given fields replaced with the
432    /// new values.
433    ///
434    /// This method is obsolete and will be deprecated in a future release:
435    /// please use the [`TabBarThemeData::copy_with`] instead.
436    ///
437    /// Dart's named arguments are the `with_*` setters on the copy
438    /// (`theme.copy_with().with_divider_height(2.0)`). As in Dart, the copy carries neither the
439    /// key nor the child, and holds the properties, never a [`data`](Self::data).
440    pub fn copy_with(&self) -> TabBarTheme {
441        TabBarTheme {
442            key: None,
443            data: None,
444            indicator: self.indicator().cloned(),
445            indicator_color: self.indicator_color(),
446            indicator_size: self.indicator_size(),
447            divider_color: self.divider_color(),
448            divider_height: self.divider_height(),
449            label_color: self.label_color().cloned(),
450            label_padding: self.label_padding(),
451            label_style: self.label_style().cloned(),
452            unselected_label_color: self.unselected_label_color(),
453            unselected_label_style: self.unselected_label_style().cloned(),
454            overlay_color: self.overlay_color(),
455            splash_factory: self.splash_factory(),
456            mouse_cursor: self.mouse_cursor(),
457            tab_alignment: self.tab_alignment(),
458            text_scaler: self.text_scaler().cloned(),
459            indicator_animation: self.indicator_animation(),
460            child: SizedBox::new().into_widget(),
461        }
462    }
463
464    /// Returns the configuration [`data`](Self::data) from the closest [`TabBarTheme`] ancestor.
465    /// If there is no ancestor, it returns `ThemeData::tab_bar_theme`.
466    ///
467    /// Typical usage is as follows:
468    ///
469    /// ```text
470    /// let theme = TabBarTheme::of(app, context);
471    /// ```
472    pub fn of(app: &mut App, context: BuildContext) -> TabBarThemeData {
473        match context.depend_on_inherited_widget_of_exact_type::<TabBarTheme>(app) {
474            Some(tab_bar_theme) => tab_bar_theme.data(),
475            None => Theme::of(app, context).tab_bar_theme.clone(),
476        }
477    }
478
479    /// Linearly interpolate between two tab bar themes.
480    ///
481    /// {@macro dart.ui.shadow.lerp}
482    ///
483    /// This method is obsolete and will be deprecated in a future release:
484    /// please use the [`TabBarThemeData::lerp`] instead.
485    pub fn lerp(a: &TabBarTheme, b: &TabBarTheme, t: f64) -> TabBarTheme {
486        if std::ptr::eq(a, b) {
487            return a.clone();
488        }
489        TabBarTheme {
490            key: None,
491            data: None,
492            indicator: DecorationRef::lerp(a.indicator(), b.indicator(), t),
493            indicator_color: Color::lerp(a.indicator_color(), b.indicator_color(), t),
494            indicator_size: if t < 0.5 {
495                a.indicator_size()
496            } else {
497                b.indicator_size()
498            },
499            divider_color: Color::lerp(a.divider_color(), b.divider_color(), t),
500            divider_height: if t < 0.5 {
501                a.divider_height()
502            } else {
503                b.divider_height()
504            },
505            label_color: AnyColor::lerp(a.label_color(), b.label_color(), t).map(AnyColor::new),
506            label_padding: EdgeInsetsGeometry::lerp(a.label_padding(), b.label_padding(), t),
507            label_style: TextStyle::lerp(a.label_style(), b.label_style(), t),
508            unselected_label_color: Color::lerp(
509                a.unselected_label_color(),
510                b.unselected_label_color(),
511                t,
512            ),
513            unselected_label_style: TextStyle::lerp(
514                a.unselected_label_style(),
515                b.unselected_label_style(),
516                t,
517            ),
518            overlay_color: <dyn WidgetStateProperty<Option<Color>>>::lerp_optional(
519                a.overlay_color(),
520                b.overlay_color(),
521                t,
522                Color::lerp,
523            ),
524            splash_factory: if t < 0.5 {
525                a.splash_factory()
526            } else {
527                b.splash_factory()
528            },
529            mouse_cursor: if t < 0.5 {
530                a.mouse_cursor()
531            } else {
532                b.mouse_cursor()
533            },
534            tab_alignment: if t < 0.5 {
535                a.tab_alignment()
536            } else {
537                b.tab_alignment()
538            },
539            text_scaler: if t < 0.5 {
540                a.text_scaler().cloned()
541            } else {
542                b.text_scaler().cloned()
543            },
544            indicator_animation: if t < 0.5 {
545                a.indicator_animation()
546            } else {
547                b.indicator_animation()
548            },
549            child: SizedBox::new().into_widget(),
550        }
551    }
552
553    /// Dart's constructor assert: a `data` takes the place of every property.
554    fn has_no_property(&self) -> bool {
555        self.indicator.is_none()
556            && self.indicator_color.is_none()
557            && self.indicator_size.is_none()
558            && self.divider_color.is_none()
559            && self.divider_height.is_none()
560            && self.label_color.is_none()
561            && self.label_padding.is_none()
562            && self.label_style.is_none()
563            && self.unselected_label_color.is_none()
564            && self.unselected_label_style.is_none()
565            && self.overlay_color.is_none()
566            && self.splash_factory.is_none()
567            && self.mouse_cursor.is_none()
568            && self.tab_alignment.is_none()
569            && self.text_scaler.is_none()
570            && self.indicator_animation.is_none()
571    }
572}
573
574impl Default for TabBarTheme {
575    fn default() -> TabBarTheme {
576        TabBarTheme::new()
577    }
578}
579
580impl InheritedTheme for TabBarTheme {
581    fn wrap(&self, _app: &mut App, _context: BuildContext, child: WidgetRef) -> WidgetRef {
582        TabBarTheme::new()
583            .with_data(self.data())
584            .child(child)
585            .into_widget()
586    }
587}
588
589impl InheritedWidget for TabBarTheme {
590    fn key(&self) -> Option<&KeyRef> {
591        self.key.as_ref()
592    }
593
594    fn child(&self) -> &WidgetRef {
595        &self.child
596    }
597
598    fn update_should_notify(&self, old_widget: &TabBarTheme) -> bool {
599        self.data() != old_widget.data()
600    }
601
602    fn as_inherited_theme(&self) -> Option<&dyn InheritedTheme> {
603        Some(self)
604    }
605}
606
607/// Defines default property values for descendant `TabBar` widgets.
608///
609/// Descendant widgets obtain the current [`TabBarThemeData`] object using
610/// [`TabBarTheme::of`]. Instances of [`TabBarThemeData`] can be customized
611/// with [`TabBarThemeData::copy_with`].
612///
613/// Typically a [`TabBarThemeData`] is specified as part of the overall `Theme`
614/// with `ThemeData::tab_bar_theme`.
615///
616/// All [`TabBarThemeData`] properties are `null` by default. When null, the `TabBar`
617/// will use the values from `ThemeData` if they exist, otherwise it will
618/// provide its own defaults. See the individual `TabBar` properties for details.
619///
620/// See also:
621///
622///  * `TabBar`, which displays a row of tabs.
623///  * `ThemeData`, which describes the overall theme information for the
624///    application.
625#[derive(Clone, Debug, Default)]
626pub struct TabBarThemeData {
627    /// Overrides the default value for `TabBar::indicator`.
628    pub indicator: Option<DecorationRef>,
629
630    /// Overrides the default value for `TabBar::indicator_color`.
631    pub indicator_color: Option<Color>,
632
633    /// Overrides the default value for `TabBar::indicator_size`.
634    pub indicator_size: Option<TabBarIndicatorSize>,
635
636    /// Overrides the default value for `TabBar::divider_color`.
637    pub divider_color: Option<Color>,
638
639    /// Overrides the default value for `TabBar::divider_height`.
640    pub divider_height: Option<f64>,
641
642    /// Overrides the default value for `TabBar::label_color`.
643    ///
644    /// If [`label_color`](Self::label_color) is a `WidgetStateColor`, then the effective color will
645    /// depend on the `WidgetState::Selected` state, i.e. if the `Tab` is
646    /// selected or not. In case of unselected state, this `WidgetStateColor`'s
647    /// resolved color will be used even if `TabBar::unselected_label_color` or
648    /// [`unselected_label_color`](Self::unselected_label_color) is non-null.
649    pub label_color: Option<AnyColor>,
650
651    /// Overrides the default value for `TabBar::label_padding`.
652    ///
653    /// If there are few tabs with both icon and text and few
654    /// tabs with only icon or text, this padding is vertically
655    /// adjusted to provide uniform padding to all tabs.
656    pub label_padding: Option<EdgeInsetsGeometry>,
657
658    /// Overrides the default value for `TabBar::label_style`.
659    pub label_style: Option<TextStyle>,
660
661    /// Overrides the default value for `TabBar::unselected_label_color`.
662    pub unselected_label_color: Option<Color>,
663
664    /// Overrides the default value for `TabBar::unselected_label_style`.
665    pub unselected_label_style: Option<TextStyle>,
666
667    /// Overrides the default value for `TabBar::overlay_color`.
668    pub overlay_color: Option<WidgetStatePropertyRef<Option<Color>>>,
669
670    /// Overrides the default value for `TabBar::splash_factory`.
671    pub splash_factory: Option<InteractiveInkFeatureFactoryRef>,
672
673    /// The cursor for a mouse pointer when it enters or is hovering over the
674    /// individual tab widgets.
675    ///
676    /// If `TabBar::mouse_cursor` is a `WidgetStateMouseCursor`,
677    /// `WidgetStateProperty::resolve` is used for the following `WidgetState`s:
678    ///
679    ///  * `WidgetState::Selected`.
680    ///
681    /// If specified, overrides the default value of `TabBar::mouse_cursor`.
682    pub mouse_cursor: Option<WidgetStatePropertyRef<Option<MouseCursorRef>>>,
683
684    /// Overrides the default value for `TabBar::tab_alignment`.
685    pub tab_alignment: Option<TabAlignment>,
686
687    /// Overrides the default value for `TabBar::text_scaler`.
688    pub text_scaler: Option<TextScaler>,
689
690    /// Overrides the default value for `TabBar::indicator_animation`.
691    pub indicator_animation: Option<TabIndicatorAnimation>,
692
693    /// Defines the clipping radius of splashes that extend outside the bounds of the tab.
694    pub splash_border_radius: Option<BorderRadius>,
695}
696
697crate::theme_data_getters::theme_data_getters! {
698    /// Dart's getters of `TabBarThemeData`: the theme data answers with its fields, and a defaults
699    /// subclass (Dart's `_...Defaults...(context)`) computes the ones it overrides when they
700    /// are read.
701    pub trait TabBarThemeDataGetters for TabBarThemeData, fields: tab_bar_theme_data {
702        indicator: Option<DecorationRef>,
703        indicator_color: Option<Color>,
704        indicator_size: Option<TabBarIndicatorSize>,
705        divider_color: Option<Color>,
706        divider_height: Option<f64>,
707        label_color: Option<AnyColor>,
708        label_padding: Option<EdgeInsetsGeometry>,
709        label_style: Option<TextStyle>,
710        unselected_label_color: Option<Color>,
711        unselected_label_style: Option<TextStyle>,
712        overlay_color: Option<WidgetStatePropertyRef<Option<Color>>>,
713        splash_factory: Option<InteractiveInkFeatureFactoryRef>,
714        mouse_cursor: Option<WidgetStatePropertyRef<Option<MouseCursorRef>>>,
715        tab_alignment: Option<TabAlignment>,
716        text_scaler: Option<TextScaler>,
717        indicator_animation: Option<TabIndicatorAnimation>,
718        splash_border_radius: Option<BorderRadius>,
719    }
720}
721
722impl TabBarThemeData {
723    /// Creates a tab bar theme that can be used with `ThemeData::tab_bar_theme`; Dart's
724    /// named arguments are the fluent setters.
725    pub fn new() -> TabBarThemeData {
726        TabBarThemeData::default()
727    }
728
729    /// Dart `TabBarThemeData(indicator:)`.
730    pub fn indicator(mut self, indicator: impl Into<DecorationRef>) -> TabBarThemeData {
731        self.indicator = Some(indicator.into());
732        self
733    }
734
735    /// Dart `TabBarThemeData(indicatorColor:)`.
736    pub fn indicator_color(mut self, indicator_color: Color) -> TabBarThemeData {
737        self.indicator_color = Some(indicator_color);
738        self
739    }
740
741    /// Dart `TabBarThemeData(indicatorSize:)`.
742    pub fn indicator_size(mut self, indicator_size: TabBarIndicatorSize) -> TabBarThemeData {
743        self.indicator_size = Some(indicator_size);
744        self
745    }
746
747    /// Dart `TabBarThemeData(dividerColor:)`.
748    pub fn divider_color(mut self, divider_color: Color) -> TabBarThemeData {
749        self.divider_color = Some(divider_color);
750        self
751    }
752
753    /// Dart `TabBarThemeData(dividerHeight:)`.
754    pub fn divider_height(mut self, divider_height: f64) -> TabBarThemeData {
755        self.divider_height = Some(divider_height);
756        self
757    }
758
759    /// Dart `TabBarThemeData(labelColor:)`.
760    pub fn label_color(mut self, label_color: impl Into<AnyColor>) -> TabBarThemeData {
761        self.label_color = Some(label_color.into());
762        self
763    }
764
765    /// Dart `TabBarThemeData(labelPadding:)`.
766    pub fn label_padding(
767        mut self,
768        label_padding: impl Into<EdgeInsetsGeometry>,
769    ) -> TabBarThemeData {
770        self.label_padding = Some(label_padding.into());
771        self
772    }
773
774    /// Dart `TabBarThemeData(labelStyle:)`.
775    pub fn label_style(mut self, label_style: TextStyle) -> TabBarThemeData {
776        self.label_style = Some(label_style);
777        self
778    }
779
780    /// Dart `TabBarThemeData(unselectedLabelColor:)`.
781    pub fn unselected_label_color(mut self, unselected_label_color: Color) -> TabBarThemeData {
782        self.unselected_label_color = Some(unselected_label_color);
783        self
784    }
785
786    /// Dart `TabBarThemeData(unselectedLabelStyle:)`.
787    pub fn unselected_label_style(mut self, unselected_label_style: TextStyle) -> TabBarThemeData {
788        self.unselected_label_style = Some(unselected_label_style);
789        self
790    }
791
792    /// Dart `TabBarThemeData(overlayColor:)`.
793    pub fn overlay_color(
794        mut self,
795        overlay_color: WidgetStatePropertyRef<Option<Color>>,
796    ) -> TabBarThemeData {
797        self.overlay_color = Some(overlay_color);
798        self
799    }
800
801    /// Dart `TabBarThemeData(splashFactory:)`.
802    pub fn splash_factory(
803        mut self,
804        splash_factory: InteractiveInkFeatureFactoryRef,
805    ) -> TabBarThemeData {
806        self.splash_factory = Some(splash_factory);
807        self
808    }
809
810    /// Dart `TabBarThemeData(mouseCursor:)`.
811    pub fn mouse_cursor(
812        mut self,
813        mouse_cursor: WidgetStatePropertyRef<Option<MouseCursorRef>>,
814    ) -> TabBarThemeData {
815        self.mouse_cursor = Some(mouse_cursor);
816        self
817    }
818
819    /// Dart `TabBarThemeData(tabAlignment:)`.
820    pub fn tab_alignment(mut self, tab_alignment: TabAlignment) -> TabBarThemeData {
821        self.tab_alignment = Some(tab_alignment);
822        self
823    }
824
825    /// Dart `TabBarThemeData(textScaler:)`.
826    pub fn text_scaler(mut self, text_scaler: TextScaler) -> TabBarThemeData {
827        self.text_scaler = Some(text_scaler);
828        self
829    }
830
831    /// Dart `TabBarThemeData(indicatorAnimation:)`.
832    pub fn indicator_animation(
833        mut self,
834        indicator_animation: TabIndicatorAnimation,
835    ) -> TabBarThemeData {
836        self.indicator_animation = Some(indicator_animation);
837        self
838    }
839
840    /// Dart `TabBarThemeData(splashBorderRadius:)`.
841    pub fn splash_border_radius(mut self, splash_border_radius: BorderRadius) -> TabBarThemeData {
842        self.splash_border_radius = Some(splash_border_radius);
843        self
844    }
845
846    /// Creates a copy of this object but with the given fields replaced with the
847    /// new values.
848    ///
849    /// Dart's named arguments are the fluent setters on the copy
850    /// (`data.copy_with().divider_height(2.0)`).
851    pub fn copy_with(&self) -> TabBarThemeData {
852        self.clone()
853    }
854
855    /// Linearly interpolate between two tab bar themes.
856    ///
857    /// {@macro dart.ui.shadow.lerp}
858    pub fn lerp(a: &TabBarThemeData, b: &TabBarThemeData, t: f64) -> TabBarThemeData {
859        if std::ptr::eq(a, b) {
860            return a.clone();
861        }
862        TabBarThemeData {
863            indicator: DecorationRef::lerp(a.indicator.as_ref(), b.indicator.as_ref(), t),
864            indicator_color: Color::lerp(a.indicator_color, b.indicator_color, t),
865            indicator_size: if t < 0.5 {
866                a.indicator_size
867            } else {
868                b.indicator_size
869            },
870            divider_color: Color::lerp(a.divider_color, b.divider_color, t),
871            divider_height: if t < 0.5 {
872                a.divider_height
873            } else {
874                b.divider_height
875            },
876            label_color: AnyColor::lerp(a.label_color.as_ref(), b.label_color.as_ref(), t)
877                .map(AnyColor::new),
878            label_padding: EdgeInsetsGeometry::lerp(a.label_padding, b.label_padding, t),
879            label_style: TextStyle::lerp(a.label_style.as_ref(), b.label_style.as_ref(), t),
880            unselected_label_color: Color::lerp(
881                a.unselected_label_color,
882                b.unselected_label_color,
883                t,
884            ),
885            unselected_label_style: TextStyle::lerp(
886                a.unselected_label_style.as_ref(),
887                b.unselected_label_style.as_ref(),
888                t,
889            ),
890            overlay_color: <dyn WidgetStateProperty<Option<Color>>>::lerp_optional(
891                a.overlay_color.clone(),
892                b.overlay_color.clone(),
893                t,
894                Color::lerp,
895            ),
896            splash_factory: if t < 0.5 {
897                a.splash_factory.clone()
898            } else {
899                b.splash_factory.clone()
900            },
901            mouse_cursor: if t < 0.5 {
902                a.mouse_cursor.clone()
903            } else {
904                b.mouse_cursor.clone()
905            },
906            tab_alignment: if t < 0.5 {
907                a.tab_alignment
908            } else {
909                b.tab_alignment
910            },
911            text_scaler: if t < 0.5 {
912                a.text_scaler.clone()
913            } else {
914                b.text_scaler.clone()
915            },
916            indicator_animation: if t < 0.5 {
917                a.indicator_animation
918            } else {
919                b.indicator_animation
920            },
921            // Dart lerps `a.splashBorderRadius` with itself.
922            splash_border_radius: BorderRadius::lerp(
923                a.splash_border_radius,
924                a.splash_border_radius,
925                t,
926            ),
927        }
928    }
929}
930
931impl PartialEq for TabBarThemeData {
932    fn eq(&self, other: &TabBarThemeData) -> bool {
933        if std::ptr::eq(self, other) {
934            return true;
935        }
936        other.indicator == self.indicator
937            && other.indicator_color == self.indicator_color
938            && other.indicator_size == self.indicator_size
939            && other.divider_color == self.divider_color
940            && other.divider_height == self.divider_height
941            && other.label_color == self.label_color
942            && other.label_padding == self.label_padding
943            && other.label_style == self.label_style
944            && other.unselected_label_color == self.unselected_label_color
945            && other.unselected_label_style == self.unselected_label_style
946            && other.overlay_color == self.overlay_color
947            && other.splash_factory == self.splash_factory
948            && other.mouse_cursor == self.mouse_cursor
949            && other.tab_alignment == self.tab_alignment
950            && other.text_scaler == self.text_scaler
951            && other.indicator_animation == self.indicator_animation
952            && other.splash_border_radius == self.splash_border_radius
953    }
954}
955
956impl waft_foundation::Diagnosticable for TabBarThemeData {
957    fn debug_fill_properties(&self, properties: &mut waft_foundation::DiagnosticPropertiesBuilder) {
958        properties.add(
959            DiagnosticsProperty::<DecorationRef>::new("indicator", self.indicator.clone())
960                .default_value(None),
961        );
962        properties.add(
963            DiagnosticsProperty::<Color>::new("indicatorColor", self.indicator_color)
964                .default_value(None),
965        );
966        properties.add(
967            DiagnosticsProperty::<waft_foundation::DartEnum<TabBarIndicatorSize>>::new(
968                "indicatorSize",
969                self.indicator_size.map(waft_foundation::DartEnum),
970            )
971            .default_value(None),
972        );
973        properties.add(
974            DiagnosticsProperty::<Color>::new("dividerColor", self.divider_color)
975                .default_value(None),
976        );
977        properties.add(
978            DiagnosticsProperty::<f64>::new("dividerHeight", self.divider_height)
979                .default_value(None),
980        );
981        properties.add(
982            DiagnosticsProperty::<AnyColor>::new("labelColor", self.label_color.clone())
983                .default_value(None),
984        );
985        properties.add(
986            DiagnosticsProperty::<EdgeInsetsGeometry>::new("labelPadding", self.label_padding)
987                .default_value(None),
988        );
989        properties.add(
990            DiagnosticsProperty::<TextStyle>::new("labelStyle", self.label_style.clone())
991                .default_value(None),
992        );
993        properties.add(
994            DiagnosticsProperty::<Color>::new("unselectedLabelColor", self.unselected_label_color)
995                .default_value(None),
996        );
997        properties.add(
998            DiagnosticsProperty::<TextStyle>::new(
999                "unselectedLabelStyle",
1000                self.unselected_label_style.clone(),
1001            )
1002            .default_value(None),
1003        );
1004        properties.add(
1005            DiagnosticsProperty::<String>::new(
1006                "overlayColor",
1007                self.overlay_color
1008                    .as_deref()
1009                    .map(|property| property.to_string()),
1010            )
1011            .default_value(None),
1012        );
1013        properties.add(DiagnosticsProperty::<waft_foundation::InstanceOf<InteractiveInkFeatureFactoryRef>>::new("splashFactory", self.splash_factory.clone().map(waft_foundation::InstanceOf)).default_value(None));
1014        properties.add(
1015            DiagnosticsProperty::<String>::new(
1016                "mouseCursor",
1017                self.mouse_cursor
1018                    .as_deref()
1019                    .map(|property| property.to_string()),
1020            )
1021            .default_value(None),
1022        );
1023        properties.add(
1024            DiagnosticsProperty::<waft_foundation::DartEnum<TabAlignment>>::new(
1025                "tabAlignment",
1026                self.tab_alignment.map(waft_foundation::DartEnum),
1027            )
1028            .default_value(None),
1029        );
1030        properties.add(
1031            DiagnosticsProperty::<TextScaler>::new("textScaler", self.text_scaler.clone())
1032                .default_value(None),
1033        );
1034        properties.add(
1035            DiagnosticsProperty::<waft_foundation::DartEnum<TabIndicatorAnimation>>::new(
1036                "indicatorAnimation",
1037                self.indicator_animation.map(waft_foundation::DartEnum),
1038            )
1039            .default_value(None),
1040        );
1041        properties.add(
1042            DiagnosticsProperty::<BorderRadius>::new(
1043                "splashBorderRadius",
1044                self.splash_border_radius,
1045            )
1046            .default_value(None),
1047        );
1048    }
1049}
1050
1051impl std::fmt::Display for TabBarThemeData {
1052    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1053        f.write_str(&waft_foundation::Diagnosticable::to_string(self))
1054    }
1055}
1056
1057#[cfg(test)]
1058mod tests {
1059    //! Ported from `test/tab_bar_theme_test.dart`: the two cases that build no `TabBar` here,
1060    //! those that build one in `tab_bar_cases`; the `debugFillProperties` cases wait for
1061    //! diagnostics, `hashCode` for `Hash`, and the golden cases are not ported. The cases
1062    //! below the first two are not in Dart: they pin what Dart's `TabBarTheme`, `of` and `lerp`
1063    //! do, which its file checks only through a `TabBar`.
1064
1065    use waft_painting::{BorderSide, BorderStyle, BoxDecoration, EdgeInsets};
1066    use waft_widgets::WidgetStateColor;
1067
1068    use waft_widgets::testing::test_widgets;
1069
1070    use super::*;
1071    use crate::colors::Colors;
1072    use crate::drawer_theme::tests::probe;
1073    use crate::drawer_theme::tests::theme_seen_through_capture;
1074    use crate::ink_ripple::InkRipple;
1075    use crate::tab_indicator::UnderlineTabIndicator;
1076    use crate::theme_data::ThemeData;
1077
1078    #[test]
1079    fn tab_bar_theme_data_copy_with_equality_and_defaults() {
1080        assert_eq!(TabBarThemeData::new(), TabBarThemeData::new().copy_with());
1081
1082        let theme = TabBarThemeData::new();
1083        assert!(theme.indicator.is_none());
1084        assert_eq!(theme.indicator_color, None);
1085        assert_eq!(theme.indicator_size, None);
1086        assert_eq!(theme.divider_color, None);
1087        assert_eq!(theme.divider_height, None);
1088        assert_eq!(theme.label_color, None);
1089        assert_eq!(theme.label_padding, None);
1090        assert_eq!(theme.label_style, None);
1091        assert_eq!(theme.unselected_label_color, None);
1092        assert_eq!(theme.unselected_label_style, None);
1093        assert!(theme.overlay_color.is_none());
1094        assert!(theme.splash_factory.is_none());
1095        assert!(theme.mouse_cursor.is_none());
1096        assert_eq!(theme.tab_alignment, None);
1097        assert_eq!(theme.text_scaler, None);
1098        assert_eq!(theme.indicator_animation, None);
1099    }
1100
1101    #[test]
1102    fn tab_bar_theme_data_lerp_of_a_theme_with_itself_is_that_theme() {
1103        let theme = TabBarThemeData::new().divider_height(3.0);
1104        assert_eq!(TabBarThemeData::lerp(&theme, &theme, 0.5), theme);
1105    }
1106
1107    #[test]
1108    fn tab_bar_theme_data_copies_compare_by_their_fields() {
1109        let theme = TabBarThemeData::new()
1110            .indicator_color(Colors::RED.primary())
1111            .indicator_size(TabBarIndicatorSize::Label)
1112            .divider_height(2.0)
1113            .label_color(Colors::BLACK)
1114            .label_padding(EdgeInsets::all(4.0))
1115            .tab_alignment(TabAlignment::Center)
1116            .indicator_animation(TabIndicatorAnimation::Elastic)
1117            .splash_border_radius(BorderRadius::circular(8.0))
1118            .splash_factory(InkRipple::splash_factory());
1119
1120        assert_eq!(theme.copy_with(), theme);
1121        assert_eq!(
1122            theme.copy_with().divider_height(5.0).divider_height,
1123            Some(5.0)
1124        );
1125        assert_eq!(
1126            theme.copy_with().divider_height(5.0).indicator_color,
1127            theme.indicator_color
1128        );
1129        assert_ne!(theme.copy_with().divider_height(5.0), theme);
1130        assert_ne!(theme.copy_with().tab_alignment(TabAlignment::Fill), theme);
1131        // Dart compares a `resolveWith` property and a splash factory by identity.
1132        let overlay = <dyn WidgetStateProperty<Option<Color>>>::resolve_with(|_| None);
1133        let with_overlay = theme.copy_with().overlay_color(overlay.clone());
1134        assert_eq!(with_overlay.copy_with(), with_overlay);
1135        assert_ne!(
1136            with_overlay,
1137            theme.copy_with().overlay_color(
1138                <dyn WidgetStateProperty<Option<Color>>>::resolve_with(|_| None)
1139            )
1140        );
1141        // A `BoxDecoration` compares by its fields, as Dart's `==` does.
1142        let decorated = theme
1143            .copy_with()
1144            .indicator(BoxDecoration::new().color(Colors::BLUE.primary()));
1145        assert_eq!(decorated.copy_with(), decorated);
1146        // An `UnderlineTabIndicator` does not override `==`: a copy shares the one indicator
1147        // and is equal, and another indicator of the same fields is not.
1148        let underlined = theme.copy_with().indicator(UnderlineTabIndicator::new());
1149        assert_eq!(underlined.copy_with(), underlined);
1150        assert_eq!(underlined.clone(), underlined);
1151        assert_ne!(
1152            theme.copy_with().indicator(UnderlineTabIndicator::new()),
1153            underlined
1154        );
1155    }
1156
1157    #[test]
1158    fn tab_bar_theme_data_lerps_each_field() {
1159        let a = TabBarThemeData::new()
1160            .indicator_color(Colors::BLACK)
1161            .indicator_size(TabBarIndicatorSize::Tab)
1162            .divider_color(Colors::BLACK)
1163            .divider_height(1.0)
1164            .label_color(Colors::BLACK)
1165            .label_padding(EdgeInsets::all(10.0))
1166            .unselected_label_color(Colors::BLACK)
1167            .tab_alignment(TabAlignment::Start)
1168            .indicator_animation(TabIndicatorAnimation::Linear)
1169            .splash_border_radius(BorderRadius::circular(4.0));
1170        let b = TabBarThemeData::new()
1171            .indicator_color(Colors::WHITE)
1172            .indicator_size(TabBarIndicatorSize::Label)
1173            .divider_color(Colors::WHITE)
1174            .divider_height(3.0)
1175            .label_color(Colors::WHITE)
1176            .label_padding(EdgeInsets::all(30.0))
1177            .unselected_label_color(Colors::WHITE)
1178            .tab_alignment(TabAlignment::Center)
1179            .indicator_animation(TabIndicatorAnimation::Elastic)
1180            .splash_border_radius(BorderRadius::circular(12.0));
1181
1182        let mid_gray = Color::lerp(Some(Colors::BLACK), Some(Colors::WHITE), 0.25);
1183        let before = TabBarThemeData::lerp(&a, &b, 0.25);
1184        assert_eq!(before.indicator_color, mid_gray);
1185        assert_eq!(before.indicator_size, Some(TabBarIndicatorSize::Tab));
1186        assert_eq!(before.divider_color, mid_gray);
1187        assert_eq!(before.divider_height, Some(1.0));
1188        assert_eq!(before.label_color, mid_gray.map(AnyColor::new));
1189        assert_eq!(before.label_padding, Some(EdgeInsets::all(15.0).into()));
1190        assert_eq!(before.unselected_label_color, mid_gray);
1191        assert_eq!(before.tab_alignment, Some(TabAlignment::Start));
1192        assert_eq!(
1193            before.indicator_animation,
1194            Some(TabIndicatorAnimation::Linear)
1195        );
1196
1197        let after = TabBarThemeData::lerp(&a, &b, 0.75);
1198        assert_eq!(after.indicator_size, Some(TabBarIndicatorSize::Label));
1199        assert_eq!(after.divider_height, Some(3.0));
1200        assert_eq!(after.tab_alignment, Some(TabAlignment::Center));
1201        assert_eq!(
1202            after.indicator_animation,
1203            Some(TabIndicatorAnimation::Elastic)
1204        );
1205        // Dart lerps the first theme's splash border radius with itself.
1206        assert_eq!(after.splash_border_radius, a.splash_border_radius);
1207    }
1208
1209    #[test]
1210    fn tab_bar_theme_data_lerp_drops_a_widget_state_label_color() {
1211        let a = TabBarThemeData::new()
1212            .label_color(WidgetStateColor::resolve_with(|_| Colors::RED.primary()));
1213        let b = TabBarThemeData::new().label_color(Colors::RED.primary());
1214        let lerped = TabBarThemeData::lerp(&a, &b, 0.5)
1215            .label_color
1216            .expect("both themes have a label color");
1217        assert!(!lerped.has_extension());
1218    }
1219
1220    #[test]
1221    fn tab_bar_theme_reads_its_properties_or_its_data() {
1222        let indicator = UnderlineTabIndicator::new().border_side(BorderSide::new(
1223            Colors::RED.primary(),
1224            3.0,
1225            BorderStyle::Solid,
1226            BorderSide::STROKE_ALIGN_INSIDE,
1227        ));
1228        let by_properties = TabBarTheme::new()
1229            .with_indicator(indicator.clone())
1230            .with_indicator_color(Colors::RED.primary())
1231            .with_indicator_size(TabBarIndicatorSize::Label)
1232            .with_divider_color(Colors::BLUE.primary())
1233            .with_divider_height(2.0)
1234            .with_label_color(Colors::BLACK)
1235            .with_label_padding(EdgeInsets::all(4.0))
1236            .with_unselected_label_color(Colors::WHITE)
1237            .with_tab_alignment(TabAlignment::Center)
1238            .with_text_scaler(TextScaler::linear(2.0))
1239            .with_indicator_animation(TabIndicatorAnimation::Elastic);
1240        let data = by_properties.data();
1241        let by_data = TabBarTheme::new().with_data(data.copy_with());
1242
1243        assert!(data.indicator.is_some());
1244        assert_eq!(data.indicator_color, Some(Colors::RED.primary()));
1245        assert_eq!(data.indicator_size, Some(TabBarIndicatorSize::Label));
1246        assert_eq!(data.divider_color, Some(Colors::BLUE.primary()));
1247        assert_eq!(data.divider_height, Some(2.0));
1248        assert_eq!(data.label_color, Some(AnyColor::new(Colors::BLACK)));
1249        assert_eq!(data.label_padding, Some(EdgeInsets::all(4.0).into()));
1250        assert_eq!(data.unselected_label_color, Some(Colors::WHITE));
1251        assert_eq!(data.tab_alignment, Some(TabAlignment::Center));
1252        assert_eq!(data.text_scaler, Some(TextScaler::linear(2.0)));
1253        assert_eq!(
1254            data.indicator_animation,
1255            Some(TabIndicatorAnimation::Elastic)
1256        );
1257        // `TabBarTheme` has no splash border radius of its own.
1258        assert_eq!(data.splash_border_radius, None);
1259
1260        assert_eq!(by_data.divider_height(), by_properties.divider_height());
1261        assert_eq!(by_data.tab_alignment(), by_properties.tab_alignment());
1262        assert_eq!(by_data.label_color(), by_properties.label_color());
1263        assert_eq!(by_data.text_scaler(), by_properties.text_scaler());
1264        assert!(by_data.indicator().is_some());
1265        assert_eq!(
1266            by_data
1267                .copy_with()
1268                .with_divider_height(5.0)
1269                .divider_height(),
1270            Some(5.0)
1271        );
1272        assert_eq!(
1273            by_data.copy_with().with_divider_height(5.0).tab_alignment(),
1274            Some(TabAlignment::Center)
1275        );
1276    }
1277
1278    #[test]
1279    fn tab_bar_theme_lerps_through_its_getters() {
1280        let a = TabBarTheme::new().with_divider_color(Colors::BLACK);
1281        let b = TabBarTheme::new().with_data(TabBarThemeData::new().divider_color(Colors::WHITE));
1282
1283        assert_eq!(
1284            TabBarTheme::lerp(&a, &b, 0.5).divider_color(),
1285            Color::lerp(Some(Colors::BLACK), Some(Colors::WHITE), 0.5)
1286        );
1287        assert_eq!(
1288            TabBarTheme::lerp(&a, &a, 0.5).divider_color(),
1289            Some(Colors::BLACK)
1290        );
1291    }
1292
1293    #[test]
1294    fn update_should_notify_only_when_the_data_differs() {
1295        let theme = |height: f64| {
1296            TabBarTheme::new().with_data(TabBarThemeData::new().divider_height(height))
1297        };
1298        let old = theme(1.0);
1299
1300        assert!(!theme(1.0).update_should_notify(&old));
1301        assert!(theme(2.0).update_should_notify(&old));
1302    }
1303
1304    #[test]
1305    fn of_returns_theme_data_tab_bar_theme_without_a_tab_bar_theme() {
1306        test_widgets(|tester| {
1307            let expected = TabBarThemeData::new().divider_height(7.0);
1308            let theme_data_tab_bar = expected.clone();
1309
1310            let seen = probe(
1311                tester,
1312                move |app, child| {
1313                    let data = ThemeData::builder()
1314                        .tab_bar_theme(theme_data_tab_bar.clone())
1315                        .build(app);
1316                    crate::theme::Theme::new(data, child).into_widget()
1317                },
1318                TabBarTheme::of,
1319            );
1320
1321            assert_eq!(seen, expected);
1322        });
1323    }
1324
1325    #[test]
1326    fn of_returns_the_closest_tab_bar_theme_over_theme_data() {
1327        test_widgets(|tester| {
1328            let local = TabBarThemeData::new().divider_height(2.0);
1329            let expected = local.clone();
1330
1331            let seen = probe(
1332                tester,
1333                move |app, child| {
1334                    let data = ThemeData::builder()
1335                        .tab_bar_theme(TabBarThemeData::new().divider_height(7.0))
1336                        .build(app);
1337                    crate::theme::Theme::new(
1338                        data,
1339                        TabBarTheme::new().with_data(local.clone()).child(child),
1340                    )
1341                    .into_widget()
1342                },
1343                TabBarTheme::of,
1344            );
1345
1346            assert_eq!(seen, expected);
1347        });
1348    }
1349
1350    #[test]
1351    fn a_captured_tab_bar_theme_is_kept_under_another_tab_bar_theme() {
1352        test_widgets(|tester| {
1353            let seen = theme_seen_through_capture(
1354                tester,
1355                |probe| {
1356                    TabBarTheme::new()
1357                        .with_data(TabBarThemeData::new().divider_height(1.0))
1358                        .child(probe)
1359                        .into_widget()
1360                },
1361                |wrapped| {
1362                    TabBarTheme::new()
1363                        .with_data(TabBarThemeData::new().divider_height(2.0))
1364                        .child(wrapped)
1365                        .into_widget()
1366                },
1367                TabBarTheme::of,
1368            );
1369
1370            assert_eq!(seen.divider_height, Some(1.0));
1371        });
1372    }
1373
1374    #[test]
1375    fn theme_data_holds_the_tab_bar_theme() {
1376        test_widgets(|tester| {
1377            let app = tester.cell.borrow();
1378            let theme = ThemeData::new(&app);
1379            assert_eq!(theme.tab_bar_theme, TabBarThemeData::new());
1380
1381            let thick = ThemeData::builder()
1382                .tab_bar_theme(TabBarThemeData::new().divider_height(4.0))
1383                .build(&app);
1384            assert_ne!(theme, thick);
1385            assert_eq!(
1386                theme
1387                    .copy_with()
1388                    .tab_bar_theme(thick.tab_bar_theme.clone())
1389                    .build(),
1390                thick
1391            );
1392
1393            let thin = ThemeData::builder()
1394                .tab_bar_theme(TabBarThemeData::new().divider_height(2.0))
1395                .build(&app);
1396            assert_eq!(
1397                ThemeData::lerp(&thin, &thick, 0.75)
1398                    .tab_bar_theme
1399                    .divider_height,
1400                Some(4.0)
1401            );
1402        });
1403    }
1404
1405    // ---- the cases that build a `TabBar` ----
1406
1407    mod tab_bar_cases {
1408        //! tab_bar_theme_test.dart's cases that build a `TabBar`; the four golden cases are
1409        //! not ported.
1410        use waft_widgets::testing::{TestPointer, WidgetTester, find, test_widgets};
1411
1412        use std::panic::{AssertUnwindSafe, catch_unwind};
1413
1414        use waft_embedder::{
1415            Color, FontStyle, FontWeight, Offset, RRect, Radius, Rect, Size, TextDirection,
1416        };
1417
1418        use waft_foundation::Ref;
1419        use waft_painting::{
1420            AlignmentGeometry, AnyColor, EdgeInsets, EdgeInsetsGeometry, TextScaler, TextStyle,
1421        };
1422        use waft_rendering::RenderBox as _;
1423        use waft_rendering::testing::{PaintCall, paints};
1424        use waft_services::SystemMouseCursors;
1425        use waft_widgets::{
1426            AnyElement, Container, DefaultWidgetsLocalizations, GlobalKey, Icon, IconTheme,
1427            IntoWidget, Localizations, MediaQuery, MediaQueryData, PreferredSizeWidgetRef,
1428            RepaintBoundary, SizedBox, WidgetRef, WidgetState, WidgetStateColor,
1429            WidgetStateMouseCursor, WidgetStateProperty,
1430        };
1431
1432        use super::super::{TabBarTheme, TabBarThemeData};
1433        use crate::app_bar::AppBar;
1434        use crate::colors::Colors;
1435        use crate::constants::K_TAB_LABEL_PADDING;
1436        use crate::icons::Icons;
1437        use crate::material::Material;
1438        use crate::material_localizations::DefaultMaterialLocalizations;
1439        use crate::scaffold::Scaffold;
1440        use crate::tab_controller::{DefaultTabController, TabController};
1441        use crate::tabs::tests::{close, first_render_box, is_line, only, painted_lines, text};
1442        use crate::tabs::{Tab, TabAlignment, TabBar, TabBarIndicatorSize, TabIndicatorAnimation};
1443        use crate::test_support::{PaintInspection, material_app};
1444        use crate::theme_data::ThemeData;
1445        use waft_widgets::testing::TestVSync;
1446
1447        const TAB_1_TEXT: &str = "tab 1";
1448
1449        /// A recorded paint's colour as `0xAARRGGBB`.
1450        fn argb32(color: waft_embedder::valo::Color) -> u32 {
1451            let channel = |value: f32| (value * 255.0).round() as u32;
1452            (channel(color.a) << 24)
1453                | (channel(color.r) << 16)
1454                | (channel(color.g) << 8)
1455                | channel(color.b)
1456        }
1457        const TAB_2_TEXT: &str = "tab 2";
1458
1459        /// Dart's `_tabs`.
1460        fn tabs() -> Vec<WidgetRef> {
1461            vec![
1462                Tab::new()
1463                    .text(TAB_1_TEXT)
1464                    .icon(Icon::new(Some(Icons::looks_one())))
1465                    .into_widget(),
1466                Tab::new()
1467                    .text(TAB_2_TEXT)
1468                    .icon(Icon::new(Some(Icons::looks_two())))
1469                    .into_widget(),
1470                Tab::new()
1471                    .text("tab 3")
1472                    .icon(Icon::new(Some(Icons::looks_3())))
1473                    .into_widget(),
1474            ]
1475        }
1476
1477        /// Dart's `_sizedTabs`, with their keys.
1478        fn sized_tabs() -> (Vec<WidgetRef>, [GlobalKey; 2]) {
1479            let keys = [GlobalKey::new(), GlobalKey::new()];
1480            let tabs = keys
1481                .iter()
1482                .map(|key| {
1483                    SizedBox::new()
1484                        .key(key.clone().into())
1485                        .width(100.0)
1486                        .height(50.0)
1487                        .into_widget()
1488                })
1489                .collect();
1490            (tabs, keys)
1491        }
1492
1493        fn controller(tester: &WidgetTester, length: usize) -> Ref<TabController> {
1494            let mut app = tester.cell.borrow_mut();
1495            TabController::new(&mut app, 0, None, length, TestVSync)
1496        }
1497
1498        /// Dart's `buildTabBar` arguments; its `useMaterial3` defaults to false, as `bool`'s.
1499        #[derive(Default)]
1500        struct Build {
1501            local_tab_bar_theme: Option<TabBarThemeData>,
1502            tab_bar_theme: Option<TabBarThemeData>,
1503            secondary_tab_bar: bool,
1504            tabs: Option<Vec<WidgetRef>>,
1505            is_scrollable: bool,
1506            use_material3: bool,
1507            font_family: Option<&'static str>,
1508            label_style: Option<TextStyle>,
1509            unselected_label_style: Option<TextStyle>,
1510        }
1511
1512        impl Build {
1513            /// Dart's `buildTabBar(..)`.
1514            fn build(self, tester: &WidgetTester) -> WidgetRef {
1515                let tabs = self.tabs.unwrap_or_else(tabs);
1516                let controller = controller(tester, tabs.len());
1517                let mut tab_bar = if self.secondary_tab_bar {
1518                    TabBar::secondary(tabs)
1519                } else {
1520                    TabBar::new(tabs)
1521                }
1522                .is_scrollable(self.is_scrollable)
1523                .controller(controller);
1524                if let Some(label_style) = self.label_style {
1525                    tab_bar = tab_bar.label_style(label_style);
1526                }
1527                if let Some(unselected_label_style) = self.unselected_label_style {
1528                    tab_bar = tab_bar.unselected_label_style(unselected_label_style);
1529                }
1530                let tab_bar = match self.local_tab_bar_theme {
1531                    Some(local) => TabBarTheme::new()
1532                        .with_data(local)
1533                        .child(tab_bar)
1534                        .into_widget(),
1535                    None => tab_bar.into_widget(),
1536                };
1537                let theme = {
1538                    let app = tester.cell.borrow();
1539                    let mut builder = ThemeData::builder().use_material3(self.use_material3);
1540                    if let Some(tab_bar_theme) = self.tab_bar_theme {
1541                        builder = builder.tab_bar_theme(tab_bar_theme);
1542                    }
1543                    if let Some(font_family) = self.font_family {
1544                        builder = builder.font_family(font_family);
1545                    }
1546                    builder.build(&app)
1547                };
1548                material_app(
1549                    theme,
1550                    Scaffold::new()
1551                        .body(RepaintBoundary::new().child(tab_bar))
1552                        .into_widget(),
1553                )
1554            }
1555        }
1556
1557        /// Dart's `ThemeData(tabBarTheme:, useMaterial3:)`.
1558        fn theme_with(
1559            tester: &WidgetTester,
1560            tab_bar_theme: Option<TabBarThemeData>,
1561            use_material3: bool,
1562        ) -> ThemeData {
1563            let app = tester.cell.borrow();
1564            let mut builder = ThemeData::builder().use_material3(use_material3);
1565            if let Some(tab_bar_theme) = tab_bar_theme {
1566                builder = builder.tab_bar_theme(tab_bar_theme);
1567            }
1568            builder.build(&app)
1569        }
1570
1571        /// Dart's `_getText(tester, text).text.style!`.
1572        fn text_style(tester: &WidgetTester, value: &str) -> TextStyle {
1573            let render = tester.render_box_of(text(tester, value));
1574            let app = tester.cell.borrow();
1575            let paragraph = render
1576                .as_object()
1577                .downcast::<waft_rendering::RenderParagraph>(&app)
1578                .expect("a Text renders a paragraph");
1579            paragraph.text(&app).style().cloned().expect("a style")
1580        }
1581
1582        fn color_of(style: &TextStyle) -> Option<Color> {
1583            style.color.as_ref().map(AnyColor::color)
1584        }
1585
1586        /// Dart's `_getIcon(tester, icon).text.style!.color`.
1587        fn icon_color(tester: &WidgetTester, icon: &waft_widgets::IconData) -> Option<Color> {
1588            let element = tester.element(find::by_icon(icon).first());
1589            color_of(&tester.glyph_style(element))
1590        }
1591
1592        /// Dart's `IconTheme.of(tester.element(find.text(text))).color`.
1593        fn icon_theme_color(tester: &WidgetTester, value: &str) -> Option<Color> {
1594            let element = text(tester, value);
1595            let mut app = tester.cell.borrow_mut();
1596            IconTheme::of(&mut app, element)
1597                .color
1598                .as_ref()
1599                .map(AnyColor::color)
1600        }
1601
1602        fn key_rect(tester: &WidgetTester, key: &GlobalKey) -> Rect {
1603            tester.get_rect(tester.render_object(key).as_box().expect("a box"))
1604        }
1605
1606        fn tab_rects(tester: &WidgetTester) -> (Rect, Rect) {
1607            let tabs: Vec<AnyElement> = find::by_type::<Tab>().evaluate(tester);
1608            (
1609                tester.get_rect(tabs[0]),
1610                tester.get_rect(*tabs.last().expect("a tab")),
1611            )
1612        }
1613
1614        fn label_padding() -> EdgeInsets {
1615            EdgeInsetsGeometry::from(K_TAB_LABEL_PADDING).resolve(Some(TextDirection::Ltr))
1616        }
1617
1618        /// The render object of the innermost `CustomPaint` under the tab bar with a painter:
1619        /// the indicator's.
1620        ///
1621        /// Dart's `paints` matcher on the tab bar records through the layers a scrollable tab
1622        /// bar's viewport pushes; `WidgetTester::pictures` reads the tab bar's own pictures
1623        /// only, so the cases ask the indicator's `CustomPaint` for what it paints there.
1624        fn indicator_paint(tester: &WidgetTester) -> waft_rendering::AnyRenderObject {
1625            let tab_bar = only::<TabBar>(tester);
1626            let paint = tester
1627                .descendants_of_type::<waft_widgets::CustomPaint>(tab_bar)
1628                .into_iter()
1629                .rfind(|element| {
1630                    tester.widget(*element, |paint: &waft_widgets::CustomPaint| {
1631                        paint.painter.is_some()
1632                    })
1633                })
1634                .expect("the indicator's CustomPaint");
1635            tester.render_box_of(paint).as_object()
1636        }
1637
1638        fn paints_line_then(
1639            tester: &WidgetTester,
1640            color: Color,
1641            stroke_width: Option<f64>,
1642            then_rrect_color: Option<Color>,
1643            then_line_color: Option<Color>,
1644        ) -> bool {
1645            let render = first_render_box::<TabBar>(tester).as_object();
1646            let mut pattern = vec![PaintCall::Line {
1647                p1: None,
1648                p2: None,
1649                color: Some(color),
1650                stroke_width,
1651            }];
1652            if let Some(color) = then_rrect_color {
1653                pattern.push(PaintCall::rrect(Some(color)));
1654            }
1655            if let Some(color) = then_line_color {
1656                pattern.push(PaintCall::Line {
1657                    p1: None,
1658                    p2: None,
1659                    color: Some(color),
1660                    stroke_width: None,
1661                });
1662            }
1663            paints(&tester.painted_ops_deep(render), &pattern).is_ok()
1664        }
1665
1666        fn paints_rrect_color(tester: &WidgetTester, color: Color) -> bool {
1667            let render = first_render_box::<TabBar>(tester).as_object();
1668            paints(
1669                &tester.painted_ops_deep(render),
1670                &[PaintCall::rrect(Some(color))],
1671            )
1672            .is_ok()
1673        }
1674
1675        // 'Local TabBarTheme overrides defaults'.
1676        #[test]
1677        fn a_local_tab_bar_theme_overrides_the_defaults() {
1678            test_widgets(|tester| {
1679                let indicator_color = Colors::GREEN.primary();
1680                const DIVIDER_COLOR: Color = Color::new(0xff000001);
1681                const DIVIDER_HEIGHT: f64 = 20.5;
1682                const LABEL_COLOR: Color = Color::new(0xff000002);
1683                const UNSELECTED_LABEL_COLOR: Color = Color::new(0xff654321);
1684
1685                let tab_bar_theme = TabBarThemeData::new()
1686                    .indicator_color(indicator_color)
1687                    .divider_color(DIVIDER_COLOR)
1688                    .divider_height(DIVIDER_HEIGHT)
1689                    .label_color(LABEL_COLOR)
1690                    .label_style(TextStyle::new().font_size(32.0))
1691                    .unselected_label_color(UNSELECTED_LABEL_COLOR)
1692                    .unselected_label_style(TextStyle::new().font_weight(FontWeight::BOLD));
1693
1694                // Test default label color and label styles.
1695                let widget = Build {
1696                    use_material3: true,
1697                    local_tab_bar_theme: Some(tab_bar_theme),
1698                    ..Build::default()
1699                }
1700                .build(tester);
1701                tester.pump_widget(widget);
1702
1703                let selected_label = text_style(tester, TAB_1_TEXT);
1704                assert_eq!(color_of(&selected_label), Some(LABEL_COLOR));
1705                assert_eq!(selected_label.font_size, Some(32.0));
1706                let unselected_label = text_style(tester, TAB_2_TEXT);
1707                assert_eq!(color_of(&unselected_label), Some(UNSELECTED_LABEL_COLOR));
1708                assert_eq!(unselected_label.font_weight, Some(FontWeight::BOLD));
1709
1710                assert!(paints_line_then(
1711                    tester,
1712                    DIVIDER_COLOR,
1713                    Some(DIVIDER_HEIGHT),
1714                    Some(indicator_color),
1715                    None
1716                ));
1717            });
1718        }
1719
1720        /// The default label padding checks of 'Tab bar defaults' (Material 3).
1721        fn check_default_label_padding(
1722            tester: &WidgetTester,
1723            keys: &[GlobalKey; 2],
1724            tab_start_offset: f64,
1725        ) {
1726            const INDICATOR_WEIGHT: f64 = 2.0;
1727            let padding = label_padding();
1728            let tab_bar = tester.get_rect(only::<TabBar>(tester));
1729            let tab_one_rect = key_rect(tester, &keys[0]);
1730            let tab_two_rect = key_rect(tester, &keys[1]);
1731
1732            // Verify tabOne coordinates.
1733            assert_eq!(tab_one_rect.left, padding.left + tab_start_offset);
1734            assert_eq!(tab_one_rect.top, padding.top);
1735            assert_eq!(
1736                tab_one_rect.bottom,
1737                tab_bar.bottom - padding.bottom - INDICATOR_WEIGHT
1738            );
1739
1740            // Verify tabTwo coordinates.
1741            if tab_start_offset > 0.0 {
1742                let tab_two_right = tab_start_offset
1743                    + padding.horizontal()
1744                    + tab_one_rect.width()
1745                    + padding.left
1746                    + tab_two_rect.width();
1747                assert_eq!(tab_two_rect.right, tab_two_right);
1748            } else {
1749                assert_eq!(tab_two_rect.right, tab_bar.width() - padding.right);
1750            }
1751            assert_eq!(tab_two_rect.top, padding.top);
1752            assert_eq!(
1753                tab_two_rect.bottom,
1754                tab_bar.bottom - padding.bottom - INDICATOR_WEIGHT
1755            );
1756
1757            // Verify tabOne and tabTwo are separated by right padding of tabOne and left padding of tabTwo.
1758            assert_eq!(
1759                tab_one_rect.right,
1760                tab_two_rect.left - padding.left - padding.right
1761            );
1762        }
1763
1764        fn material3_defaults(secondary: bool) {
1765            test_widgets(|tester| {
1766                // Test default label color and label styles.
1767                let widget = Build {
1768                    secondary_tab_bar: secondary,
1769                    use_material3: true,
1770                    ..Build::default()
1771                }
1772                .build(tester);
1773                tester.pump_widget(widget);
1774
1775                let theme = theme_with(tester, None, true);
1776                let title_small = theme.text_theme.title_small.clone().expect("titleSmall");
1777                let selected_label = text_style(tester, TAB_1_TEXT);
1778                assert_eq!(selected_label.font_family, title_small.font_family);
1779                assert_eq!(selected_label.font_size, Some(14.0));
1780                let selected_color = if secondary {
1781                    theme.color_scheme.on_surface()
1782                } else {
1783                    theme.color_scheme.primary()
1784                };
1785                assert_eq!(color_of(&selected_label), Some(selected_color));
1786                let unselected_label = text_style(tester, TAB_2_TEXT);
1787                assert_eq!(unselected_label.font_family, title_small.font_family);
1788                assert_eq!(unselected_label.font_size, Some(14.0));
1789                assert_eq!(
1790                    color_of(&unselected_label),
1791                    Some(theme.color_scheme.on_surface_variant())
1792                );
1793
1794                // Test default labelPadding. Dart's primary case builds this one without
1795                // `useMaterial3`; the `MaterialApp`'s theme animation keeps Material 3 in the
1796                // frame the case measures.
1797                let (tabs, keys) = sized_tabs();
1798                let widget = Build {
1799                    secondary_tab_bar: secondary,
1800                    tabs: Some(tabs),
1801                    is_scrollable: true,
1802                    use_material3: secondary,
1803                    ..Build::default()
1804                }
1805                .build(tester);
1806                tester.pump_widget(widget);
1807                check_default_label_padding(tester, &keys, 52.0);
1808
1809                // Test default indicator & divider color.
1810                let (then_rrect, then_line) = if secondary {
1811                    (None, Some(theme.color_scheme.primary()))
1812                } else {
1813                    (Some(theme.color_scheme.primary()), None)
1814                };
1815                assert!(paints_line_then(
1816                    tester,
1817                    theme.color_scheme.outline_variant(),
1818                    Some(1.0),
1819                    then_rrect,
1820                    then_line
1821                ));
1822            });
1823        }
1824
1825        // 'Tab bar defaults (primary)'.
1826        #[test]
1827        fn material3_primary_tab_bar_defaults() {
1828            material3_defaults(false);
1829        }
1830
1831        // 'Tab bar defaults (secondary)'.
1832        #[test]
1833        fn material3_secondary_tab_bar_defaults() {
1834            material3_defaults(true);
1835        }
1836
1837        // 'Tab bar theme overrides label color (selected)'.
1838        #[test]
1839        fn the_theme_label_color_colors_the_selected_label_and_icon() {
1840            test_widgets(|tester| {
1841                let widget = Build {
1842                    tab_bar_theme: Some(TabBarThemeData::new().label_color(Colors::BLACK)),
1843                    ..Build::default()
1844                }
1845                .build(tester);
1846                tester.pump_widget(widget);
1847
1848                assert_eq!(
1849                    color_of(&text_style(tester, TAB_1_TEXT)),
1850                    Some(Colors::BLACK)
1851                );
1852                assert_eq!(icon_color(tester, &Icons::looks_one()), Some(Colors::BLACK));
1853            });
1854        }
1855
1856        // 'Tab bar theme overrides label padding'.
1857        #[test]
1858        fn the_theme_label_padding_insets_the_tabs() {
1859            test_widgets(|tester| {
1860                const TOP_PADDING: f64 = 10.0;
1861                const BOTTOM_PADDING: f64 = 7.0;
1862                const RIGHT_PADDING: f64 = 13.0;
1863                const LEFT_PADDING: f64 = 16.0;
1864                const INDICATOR_WEIGHT: f64 = 2.0; // default value
1865
1866                let (tabs, keys) = sized_tabs();
1867                let widget = Build {
1868                    tab_bar_theme: Some(TabBarThemeData::new().label_padding(
1869                        EdgeInsets::from_ltrb(
1870                            LEFT_PADDING,
1871                            TOP_PADDING,
1872                            RIGHT_PADDING,
1873                            BOTTOM_PADDING,
1874                        ),
1875                    )),
1876                    tabs: Some(tabs),
1877                    is_scrollable: true,
1878                    ..Build::default()
1879                }
1880                .build(tester);
1881                tester.pump_widget(widget);
1882
1883                let tab_bar = tester.get_rect(only::<TabBar>(tester));
1884                let tab_one_rect = key_rect(tester, &keys[0]);
1885                let tab_two_rect = key_rect(tester, &keys[1]);
1886
1887                // verify coordinates of tabOne
1888                assert_eq!(tab_one_rect.left, LEFT_PADDING);
1889                assert_eq!(tab_one_rect.top, TOP_PADDING);
1890                assert_eq!(
1891                    tab_one_rect.bottom,
1892                    tab_bar.bottom - BOTTOM_PADDING - INDICATOR_WEIGHT
1893                );
1894
1895                // verify coordinates of tabTwo
1896                assert_eq!(tab_two_rect.right, tab_bar.width() - RIGHT_PADDING);
1897                assert_eq!(tab_two_rect.top, TOP_PADDING);
1898                assert_eq!(
1899                    tab_two_rect.bottom,
1900                    tab_bar.bottom - BOTTOM_PADDING - INDICATOR_WEIGHT
1901                );
1902
1903                // verify tabOne and tabTwo are separated by right padding of tabOne and left padding of tabTwo
1904                assert_eq!(
1905                    tab_one_rect.right,
1906                    tab_two_rect.left - LEFT_PADDING - RIGHT_PADDING
1907                );
1908            });
1909        }
1910
1911        // 'Tab bar theme overrides label styles'.
1912        #[test]
1913        fn the_theme_label_styles_style_the_labels() {
1914            test_widgets(|tester| {
1915                let widget = Build {
1916                    tab_bar_theme: Some(
1917                        TabBarThemeData::new()
1918                            .label_style(TextStyle::new().font_family("foobar"))
1919                            .unselected_label_style(TextStyle::new().font_family("baz")),
1920                    ),
1921                    ..Build::default()
1922                }
1923                .build(tester);
1924                tester.pump_widget(widget);
1925
1926                assert_eq!(
1927                    text_style(tester, TAB_1_TEXT).font_family.as_deref(),
1928                    Some("foobar")
1929                );
1930                assert_eq!(
1931                    text_style(tester, TAB_2_TEXT).font_family.as_deref(),
1932                    Some("baz")
1933                );
1934            });
1935        }
1936
1937        // 'Tab bar theme with just label style specified'.
1938        #[test]
1939        fn a_theme_with_only_a_label_style_leaves_the_unselected_label_to_the_defaults() {
1940            test_widgets(|tester| {
1941                let widget = Build {
1942                    tab_bar_theme: Some(
1943                        TabBarThemeData::new().label_style(TextStyle::new().font_family("foobar")),
1944                    ),
1945                    ..Build::default()
1946                }
1947                .build(tester);
1948                tester.pump_widget(widget);
1949
1950                assert_eq!(
1951                    text_style(tester, TAB_1_TEXT).font_family.as_deref(),
1952                    Some("foobar")
1953                );
1954                let unselected_label = text_style(tester, TAB_2_TEXT);
1955                assert_eq!(unselected_label.font_family.as_deref(), Some("Roboto"));
1956                assert_eq!(unselected_label.font_size, Some(14.0));
1957                assert_eq!(
1958                    color_of(&unselected_label),
1959                    Some(Colors::WHITE.with_alpha(0xB2))
1960                );
1961            });
1962        }
1963
1964        // 'Tab bar label styles override theme label styles'.
1965        #[test]
1966        fn the_tab_bar_label_styles_override_the_theme_label_styles() {
1967            test_widgets(|tester| {
1968                let theme = theme_with(
1969                    tester,
1970                    Some(
1971                        TabBarThemeData::new()
1972                            .label_style(TextStyle::new().font_family("3"))
1973                            .unselected_label_style(TextStyle::new().font_family("4")),
1974                    ),
1975                    true,
1976                );
1977                let controller = controller(tester, 3);
1978                tester.pump_widget(material_app(
1979                    theme,
1980                    Scaffold::new()
1981                        .body(
1982                            TabBar::new(tabs())
1983                                .controller(controller)
1984                                .label_style(TextStyle::new().font_family("1"))
1985                                .unselected_label_style(TextStyle::new().font_family("2")),
1986                        )
1987                        .into_widget(),
1988                ));
1989
1990                assert_eq!(
1991                    text_style(tester, TAB_1_TEXT).font_family.as_deref(),
1992                    Some("1")
1993                );
1994                assert_eq!(
1995                    text_style(tester, TAB_2_TEXT).font_family.as_deref(),
1996                    Some("2")
1997                );
1998            });
1999        }
2000
2001        fn label_padding_overrides_theme(use_material3: bool) {
2002            test_widgets(|tester| {
2003                const TAB_START_OFFSET: f64 = 52.0;
2004                const VERTICAL_PADDING: f64 = 10.0;
2005                const HORIZONTAL_PADDING: f64 = 10.0;
2006                const HORIZONTAL_THEME_PADDING: f64 = 20.0;
2007                const INDICATOR_WEIGHT: f64 = 2.0; // default value
2008
2009                let theme = theme_with(
2010                    tester,
2011                    Some(
2012                        TabBarThemeData::new()
2013                            .label_padding(EdgeInsetsGeometry::symmetric(20.0, 20.0)),
2014                    ),
2015                    use_material3,
2016                );
2017                let (tabs, keys) = sized_tabs();
2018                let controller = controller(tester, tabs.len());
2019                tester.pump_widget(material_app(
2020                    theme,
2021                    Scaffold::new()
2022                        .body(
2023                            RepaintBoundary::new().child(
2024                                TabBar::new(tabs)
2025                                    .is_scrollable(true)
2026                                    .controller(controller)
2027                                    .label_padding(EdgeInsetsGeometry::symmetric(
2028                                        VERTICAL_PADDING,
2029                                        HORIZONTAL_PADDING,
2030                                    )),
2031                            ),
2032                        )
2033                        .into_widget(),
2034                ));
2035
2036                let tab_bar = tester.get_rect(only::<TabBar>(tester));
2037                let tab_one_rect = key_rect(tester, &keys[0]);
2038                let tab_two_rect = key_rect(tester, &keys[1]);
2039
2040                // verify coordinates of tabOne
2041                let start = if use_material3 { TAB_START_OFFSET } else { 0.0 };
2042                assert_eq!(tab_one_rect.left, HORIZONTAL_PADDING + start);
2043                assert_eq!(tab_one_rect.top, VERTICAL_PADDING);
2044                assert_eq!(
2045                    tab_one_rect.bottom,
2046                    tab_bar.bottom - VERTICAL_PADDING - INDICATOR_WEIGHT
2047                );
2048
2049                // verify coordinates of tabTwo
2050                if use_material3 {
2051                    assert_eq!(
2052                        tab_two_rect.right,
2053                        TAB_START_OFFSET
2054                            + HORIZONTAL_THEME_PADDING
2055                            + tab_one_rect.width()
2056                            + tab_two_rect.width()
2057                            + (HORIZONTAL_THEME_PADDING / 2.0)
2058                    );
2059                } else {
2060                    assert_eq!(tab_two_rect.right, tab_bar.width() - HORIZONTAL_PADDING);
2061                }
2062                assert_eq!(tab_two_rect.top, VERTICAL_PADDING);
2063                assert_eq!(
2064                    tab_two_rect.bottom,
2065                    tab_bar.bottom - VERTICAL_PADDING - INDICATOR_WEIGHT
2066                );
2067
2068                // verify tabOne and tabTwo are separated by 2x horizontalPadding
2069                assert_eq!(
2070                    tab_one_rect.right,
2071                    tab_two_rect.left - (2.0 * HORIZONTAL_PADDING)
2072                );
2073            });
2074        }
2075
2076        // 'Material2 - Tab bar label padding overrides theme label padding'.
2077        #[test]
2078        fn material2_the_tab_bar_label_padding_overrides_the_themes() {
2079            label_padding_overrides_theme(false);
2080        }
2081
2082        // 'Material3 - Tab bar label padding overrides theme label padding'.
2083        #[test]
2084        fn material3_the_tab_bar_label_padding_overrides_the_themes() {
2085            label_padding_overrides_theme(true);
2086        }
2087
2088        // 'Tab bar theme overrides label color (unselected)'.
2089        #[test]
2090        fn the_theme_unselected_label_color_colors_the_unselected_label_and_icon() {
2091            test_widgets(|tester| {
2092                let widget = Build {
2093                    tab_bar_theme: Some(
2094                        TabBarThemeData::new().unselected_label_color(Colors::BLACK),
2095                    ),
2096                    ..Build::default()
2097                }
2098                .build(tester);
2099                tester.pump_widget(widget);
2100
2101                assert_eq!(
2102                    color_of(&text_style(tester, TAB_2_TEXT)),
2103                    Some(Colors::BLACK)
2104                );
2105                assert_eq!(icon_color(tester, &Icons::looks_two()), Some(Colors::BLACK));
2106            });
2107        }
2108
2109        // 'Tab bar theme overrides tab mouse cursor'.
2110        #[test]
2111        fn the_theme_mouse_cursor_is_the_tabs_cursor() {
2112            test_widgets(|tester| {
2113                let widget = Build {
2114                    tab_bar_theme: Some(
2115                        TabBarThemeData::new().mouse_cursor(<dyn WidgetStateProperty<
2116                            Option<waft_services::MouseCursorRef>,
2117                        >>::resolve_with(
2118                            |states| Some(WidgetStateMouseCursor::textable().resolve(states)),
2119                        )),
2120                    ),
2121                    ..Build::default()
2122                }
2123                .build(tester);
2124                tester.pump_widget(widget);
2125
2126                let tab_bar = tester.element(
2127                    find::ancestor(find::text(TAB_1_TEXT), find::by_type::<TabBar>()).first(),
2128                );
2129                let center = tester.get_rect(tab_bar).center();
2130                let mut gesture = TestPointer::mouse(1, 0);
2131                tester.add_pointer(&mut gesture, Offset::ZERO);
2132                tester.move_to(&mut gesture, center, false);
2133                tester.pump_and_settle();
2134                assert_eq!(tester.active_cursor(1), SystemMouseCursors::TEXT.into());
2135            });
2136        }
2137
2138        /// Whether pumping the `Build` that `make` gives panics, on a fresh tester: Dart's
2139        /// `tester.takeException()` after `pumpWidget`.
2140        fn pump_panics(make: impl FnOnce() -> Build + Send) -> bool {
2141            let mut panicked = false;
2142            test_widgets(|tester| {
2143                let widget = make().build(tester);
2144                panicked = catch_unwind(AssertUnwindSafe(|| tester.pump_widget(widget))).is_err();
2145            });
2146            panicked
2147        }
2148
2149        // 'TabAlignment.fill from TabBarTheme only supports non-scrollable tab bar'.
2150        #[test]
2151        fn a_theme_tab_alignment_fill_is_only_for_fixed_tab_bars() {
2152            fn theme() -> Option<TabBarThemeData> {
2153                Some(TabBarThemeData::new().tab_alignment(TabAlignment::Fill))
2154            }
2155
2156            // Test TabAlignment.fill from TabBarTheme with non-scrollable tab bar.
2157            assert!(!pump_panics(|| Build {
2158                tab_bar_theme: theme(),
2159                ..Build::default()
2160            }));
2161
2162            // Test TabAlignment.fill from TabBarTheme with scrollable tab bar.
2163            assert!(pump_panics(|| Build {
2164                tab_bar_theme: theme(),
2165                is_scrollable: true,
2166                ..Build::default()
2167            }));
2168        }
2169
2170        // 'TabAlignment.start & TabAlignment.startOffset from TabBarTheme only supports scrollable tab bar'.
2171        #[test]
2172        fn a_theme_tab_alignment_start_or_start_offset_is_only_for_scrollable_tab_bars() {
2173            for tab_alignment in [TabAlignment::Start, TabAlignment::StartOffset] {
2174                let theme = move || Some(TabBarThemeData::new().tab_alignment(tab_alignment));
2175
2176                // With a scrollable tab bar.
2177                assert!(!pump_panics(move || Build {
2178                    tab_bar_theme: theme(),
2179                    is_scrollable: true,
2180                    ..Build::default()
2181                }));
2182
2183                // With a non-scrollable tab bar.
2184                assert!(pump_panics(move || Build {
2185                    tab_bar_theme: theme(),
2186                    ..Build::default()
2187                }));
2188            }
2189        }
2190
2191        /// Dart's `MaterialApp(theme:, home: Scaffold(body: Container(alignment: topLeft, child:
2192        /// tab_bar)))` with four tabs.
2193        fn four_tabs_top_left(
2194            tester: &WidgetTester,
2195            theme: ThemeData,
2196            secondary: bool,
2197        ) -> WidgetRef {
2198            let tabs = (0..4).map(|index| Tab::new().text(format!("Tab {index}")).into_widget());
2199            let controller = controller(tester, 4);
2200            let tab_bar = if secondary {
2201                TabBar::secondary(tabs)
2202            } else {
2203                TabBar::new(tabs)
2204            }
2205            .controller(controller);
2206            material_app(
2207                theme,
2208                Scaffold::new()
2209                    .body(
2210                        Container::new()
2211                            .alignment(AlignmentGeometry::TOP_LEFT)
2212                            .child(tab_bar),
2213                    )
2214                    .into_widget(),
2215            )
2216        }
2217
2218        fn indicator_size_provides_the_indicator(
2219            use_material3: bool,
2220            secondary: bool,
2221            indicator_size: TabBarIndicatorSize,
2222            p1_x: f64,
2223            p2_x: f64,
2224        ) {
2225            test_widgets(|tester| {
2226                let theme = theme_with(
2227                    tester,
2228                    Some(TabBarThemeData::new().indicator_size(indicator_size)),
2229                    use_material3,
2230                );
2231                let widget = four_tabs_top_left(tester, theme.clone(), secondary);
2232                tester.pump_widget(widget);
2233
2234                let tab_bar_box = first_render_box::<TabBar>(tester);
2235                assert_eq!(tab_bar_box.size(&tester.cell.borrow()).height(), 48.0);
2236
2237                const INDICATOR_WEIGHT: f64 = 2.0;
2238                const INDICATOR_Y: f64 = 48.0 - (INDICATOR_WEIGHT / 2.0);
2239
2240                let lines = painted_lines(tester, tab_bar_box.as_object());
2241                #[allow(deprecated)]
2242                let indicator_color = if use_material3 {
2243                    theme.color_scheme.primary()
2244                } else {
2245                    theme.indicator_color
2246                };
2247                let indicator = lines.iter().position(|line| {
2248                    is_line(
2249                        line,
2250                        indicator_color,
2251                        Some(INDICATOR_WEIGHT),
2252                        Offset::new(p1_x, INDICATOR_Y),
2253                        Offset::new(p2_x, INDICATOR_Y),
2254                    )
2255                });
2256                assert!(indicator.is_some(), "{lines:?}");
2257                if use_material3 {
2258                    // Divider.
2259                    assert!(lines[..indicator.expect("checked")].iter().any(|line| {
2260                        line.color.to_argb32() == theme.color_scheme.outline_variant().to_argb32()
2261                            && close(line.stroke_width, 1.0, 1e-4)
2262                    }));
2263                }
2264            });
2265        }
2266
2267        // 'TabBarTheme.indicatorSize provides correct tab indicator (primary)'.
2268        #[test]
2269        fn material3_the_theme_indicator_size_tab_gives_a_tab_wide_indicator() {
2270            indicator_size_provides_the_indicator(
2271                true,
2272                false,
2273                TabBarIndicatorSize::Tab,
2274                1.0,
2275                199.0,
2276            );
2277        }
2278
2279        // 'TabBarTheme.indicatorSize provides correct tab indicator (secondary)'.
2280        #[test]
2281        fn material3_the_theme_indicator_size_label_gives_a_label_wide_secondary_indicator() {
2282            indicator_size_provides_the_indicator(
2283                true,
2284                true,
2285                TabBarIndicatorSize::Label,
2286                65.75,
2287                134.25,
2288            );
2289        }
2290
2291        /// Dart's `MaterialApp(theme:, home: Scaffold(appBar: AppBar(bottom: tab_bar)))`.
2292        fn app_bar_tab_bar(theme: ThemeData, tab_bar: TabBar) -> WidgetRef {
2293            material_app(
2294                theme,
2295                Scaffold::new()
2296                    .app_bar(PreferredSizeWidgetRef::new(
2297                        AppBar::new().bottom(PreferredSizeWidgetRef::new(tab_bar)),
2298                    ))
2299                    .into_widget(),
2300            )
2301        }
2302
2303        fn three_tabs() -> Vec<WidgetRef> {
2304            ["Tab 1", "Tab 2", "Tab 3"]
2305                .map(|label| Tab::new().text(label).into_widget())
2306                .into()
2307        }
2308
2309        // 'TabBar divider can use TabBarTheme.dividerColor & TabBarTheme.dividerHeight'.
2310        #[test]
2311        fn the_divider_takes_the_theme_divider_color_and_height() {
2312            test_widgets(|tester| {
2313                const DIVIDER_COLOR: Color = Color::new(0xff00ff00);
2314                const DIVIDER_HEIGHT: f64 = 10.0;
2315                let theme = theme_with(
2316                    tester,
2317                    Some(
2318                        TabBarThemeData::new()
2319                            .divider_color(DIVIDER_COLOR)
2320                            .divider_height(DIVIDER_HEIGHT),
2321                    ),
2322                    true,
2323                );
2324                let controller = controller(tester, 3);
2325                tester.pump_widget(app_bar_tab_bar(
2326                    theme,
2327                    TabBar::new(three_tabs()).controller(controller),
2328                ));
2329
2330                // Test divider color.
2331                let lines = painted_lines(tester, first_render_box::<TabBar>(tester).as_object());
2332                assert!(
2333                    lines
2334                        .iter()
2335                        .any(|line| line.color.to_argb32() == DIVIDER_COLOR.to_argb32()
2336                            && close(line.stroke_width, DIVIDER_HEIGHT, 1e-4))
2337                );
2338            });
2339        }
2340
2341        // 'dividerColor & dividerHeight overrides TabBarTheme.dividerColor'.
2342        #[test]
2343        fn the_tab_bar_divider_color_and_height_override_the_themes() {
2344            test_widgets(|tester| {
2345                const DIVIDER_COLOR: Color = Color::new(0xff0000ff);
2346                const DIVIDER_HEIGHT: f64 = 8.0;
2347                let theme = theme_with(
2348                    tester,
2349                    Some(
2350                        TabBarThemeData::new()
2351                            .divider_color(Colors::PINK.primary())
2352                            .divider_height(5.0),
2353                    ),
2354                    true,
2355                );
2356                let controller = controller(tester, 3);
2357                tester.pump_widget(app_bar_tab_bar(
2358                    theme,
2359                    TabBar::new(three_tabs())
2360                        .divider_color(DIVIDER_COLOR)
2361                        .divider_height(DIVIDER_HEIGHT)
2362                        .controller(controller),
2363                ));
2364
2365                // Test divider color.
2366                let lines = painted_lines(tester, first_render_box::<TabBar>(tester).as_object());
2367                assert!(
2368                    lines
2369                        .iter()
2370                        .any(|line| line.color.to_argb32() == DIVIDER_COLOR.to_argb32()
2371                            && close(line.stroke_width, DIVIDER_HEIGHT, 1e-4))
2372                );
2373            });
2374        }
2375
2376        fn two_tabs() -> Vec<WidgetRef> {
2377            ["Tab 1", "Tab 3"]
2378                .map(|label| Tab::new().text(label).into_widget())
2379                .into()
2380        }
2381
2382        /// The checks of a centered fixed tab bar 800 wide.
2383        fn check_centered(tester: &WidgetTester) {
2384            const AVAILABLE_WIDTH: f64 = 800.0;
2385            let padding = label_padding();
2386            let (tab_one_rect, tab_two_rect) = tab_rects(tester);
2387            let tab_one_left = (AVAILABLE_WIDTH / 2.0) - tab_one_rect.width() - padding.left;
2388            assert_eq!(tab_one_rect.left, tab_one_left);
2389            let tab_two_right = (AVAILABLE_WIDTH / 2.0) + tab_two_rect.width() + padding.right;
2390            assert_eq!(tab_two_rect.right, tab_two_right);
2391        }
2392
2393        /// The checks of a scrollable tab bar aligned to its start.
2394        fn check_start(tester: &WidgetTester) {
2395            let padding = label_padding();
2396            let (tab_one_rect, tab_two_rect) = tab_rects(tester);
2397            assert_eq!(tab_one_rect.left, padding.left);
2398            let tab_two_right =
2399                padding.horizontal() + tab_one_rect.width() + padding.left + tab_two_rect.width();
2400            assert_eq!(tab_two_rect.right, tab_two_right);
2401        }
2402
2403        fn respects_theme_tab_alignment(use_material3: bool) {
2404            test_widgets(|tester| {
2405                // Test non-scrollable tab bar.
2406                let theme = theme_with(
2407                    tester,
2408                    Some(TabBarThemeData::new().tab_alignment(TabAlignment::Center)),
2409                    use_material3,
2410                );
2411                let controller1 = controller(tester, 2);
2412                tester.pump_widget(app_bar_tab_bar(
2413                    theme,
2414                    TabBar::new(two_tabs()).controller(controller1),
2415                ));
2416                check_centered(tester);
2417
2418                if use_material3 {
2419                    // Test scrollable tab bar.
2420                    let theme = theme_with(
2421                        tester,
2422                        Some(TabBarThemeData::new().tab_alignment(TabAlignment::Start)),
2423                        true,
2424                    );
2425                    let controller2 = controller(tester, 2);
2426                    tester.pump_widget(app_bar_tab_bar(
2427                        theme,
2428                        TabBar::new(two_tabs())
2429                            .is_scrollable(true)
2430                            .controller(controller2),
2431                    ));
2432                    tester.pump_and_settle();
2433                    check_start(tester);
2434                }
2435            });
2436        }
2437
2438        // 'TabBar respects TabBarTheme.tabAlignment'.
2439        #[test]
2440        fn material3_the_tab_bar_takes_the_theme_tab_alignment() {
2441            respects_theme_tab_alignment(true);
2442        }
2443
2444        // 'TabBar respects TabBarTheme.tabAlignment' (Material 2).
2445        #[test]
2446        fn material2_the_tab_bar_takes_the_theme_tab_alignment() {
2447            respects_theme_tab_alignment(false);
2448        }
2449
2450        fn tab_alignment_overrides_theme(use_material3: bool) {
2451            test_widgets(|tester| {
2452                // Test non-scrollable tab bar.
2453                let theme = theme_with(
2454                    tester,
2455                    Some(TabBarThemeData::new().tab_alignment(TabAlignment::Fill)),
2456                    use_material3,
2457                );
2458                let controller1 = controller(tester, 2);
2459                tester.pump_widget(app_bar_tab_bar(
2460                    theme,
2461                    TabBar::new(two_tabs())
2462                        .tab_alignment(TabAlignment::Center)
2463                        .controller(controller1),
2464                ));
2465                check_centered(tester);
2466
2467                if use_material3 {
2468                    // Test scrollable tab bar.
2469                    let theme = theme_with(
2470                        tester,
2471                        Some(TabBarThemeData::new().tab_alignment(TabAlignment::Center)),
2472                        true,
2473                    );
2474                    let controller2 = controller(tester, 2);
2475                    tester.pump_widget(app_bar_tab_bar(
2476                        theme,
2477                        TabBar::new(two_tabs())
2478                            .is_scrollable(true)
2479                            .tab_alignment(TabAlignment::Start)
2480                            .controller(controller2),
2481                    ));
2482                    tester.pump_and_settle();
2483                    check_start(tester);
2484                }
2485            });
2486        }
2487
2488        // 'TabBar.tabAlignment overrides TabBarTheme.tabAlignment'.
2489        #[test]
2490        fn material3_the_tab_bar_tab_alignment_overrides_the_themes() {
2491            tab_alignment_overrides_theme(true);
2492        }
2493
2494        // 'TabBar.tabAlignment overrides TabBarTheme.tabAlignment' (Material 2).
2495        #[test]
2496        fn material2_the_tab_bar_tab_alignment_overrides_the_themes() {
2497            tab_alignment_overrides_theme(false);
2498        }
2499
2500        /// The selected and unselected tabs' icon colors, text colors and font styles.
2501        fn label_colors(
2502            tester: &WidgetTester,
2503        ) -> [(Option<Color>, Option<Color>, Option<FontStyle>); 2] {
2504            [TAB_1_TEXT, TAB_2_TEXT].map(|label| {
2505                let style = text_style(tester, label);
2506                (
2507                    icon_theme_color(tester, label),
2508                    color_of(&style),
2509                    style.font_style,
2510                )
2511            })
2512        }
2513
2514        const STYLE_COLOR: Color = Color::new(0xff0000ff);
2515        const UNSELECTED_STYLE_COLOR: Color = Color::new(0x950000ff);
2516
2517        fn label_style() -> TextStyle {
2518            TextStyle::new()
2519                .color(STYLE_COLOR)
2520                .font_style(FontStyle::Italic)
2521        }
2522
2523        fn unselected_label_style() -> TextStyle {
2524            TextStyle::new()
2525                .color(UNSELECTED_STYLE_COLOR)
2526                .font_style(FontStyle::Italic)
2527        }
2528
2529        fn styled_by(
2530            color: Color,
2531            unselected_color: Color,
2532        ) -> [(Option<Color>, Option<Color>, Option<FontStyle>); 2] {
2533            [
2534                (Some(color), Some(color), Some(FontStyle::Italic)),
2535                (
2536                    Some(unselected_color),
2537                    Some(unselected_color),
2538                    Some(FontStyle::Italic),
2539                ),
2540            ]
2541        }
2542
2543        // 'TabBar labels use colors from TabBarTheme.labelStyle & TabBarTheme.unselectedLabelStyle'.
2544        #[test]
2545        fn the_labels_take_their_colors_from_the_theme_label_styles() {
2546            test_widgets(|tester| {
2547                // Test tab bar with TabBarTheme labelStyle & unselectedLabelStyle.
2548                let widget = Build {
2549                    tab_bar_theme: Some(
2550                        TabBarThemeData::new()
2551                            .label_style(label_style())
2552                            .unselected_label_style(unselected_label_style()),
2553                    ),
2554                    ..Build::default()
2555                }
2556                .build(tester);
2557                tester.pump_widget(widget);
2558
2559                // Selected tab should use labelStyle color; unselected unselectedLabelStyle.
2560                assert_eq!(
2561                    label_colors(tester),
2562                    styled_by(STYLE_COLOR, UNSELECTED_STYLE_COLOR)
2563                );
2564            });
2565        }
2566
2567        const LABEL_COLOR: Color = Color::new(0xfff00000);
2568        const UNSELECTED_LABEL_COLOR: Color = Color::new(0x95ff0000);
2569
2570        // "TabBarTheme's labelColor & unselectedLabelColor override labelStyle & unselectedLabelStyle colors".
2571        #[test]
2572        fn the_theme_label_colors_override_the_theme_label_style_colors() {
2573            test_widgets(|tester| {
2574                let styles = || {
2575                    TabBarThemeData::new()
2576                        .label_style(label_style())
2577                        .unselected_label_style(unselected_label_style())
2578                };
2579                let widget = Build {
2580                    tab_bar_theme: Some(styles()),
2581                    ..Build::default()
2582                }
2583                .build(tester);
2584                tester.pump_widget(widget);
2585
2586                // Test tab bar with TabBarTheme labelStyle & unselectedLabelStyle. Dart pumps a
2587                // bar without the theme here and still expects the theme's colors, which its
2588                // first pump's controller and tabs keep; this pumps the themed bar again.
2589                let widget = Build {
2590                    tab_bar_theme: Some(styles()),
2591                    ..Build::default()
2592                }
2593                .build(tester);
2594                tester.pump_widget(widget);
2595                assert_eq!(
2596                    label_colors(tester),
2597                    styled_by(STYLE_COLOR, UNSELECTED_STYLE_COLOR)
2598                );
2599
2600                // Update the TabBarTheme with labelColor & unselectedLabelColor.
2601                let widget = Build {
2602                    tab_bar_theme: Some(
2603                        styles()
2604                            .label_color(LABEL_COLOR)
2605                            .unselected_label_color(UNSELECTED_LABEL_COLOR),
2606                    ),
2607                    ..Build::default()
2608                }
2609                .build(tester);
2610                tester.pump_widget(widget);
2611                tester.pump_and_settle();
2612                assert_eq!(
2613                    label_colors(tester),
2614                    styled_by(LABEL_COLOR, UNSELECTED_LABEL_COLOR)
2615                );
2616            });
2617        }
2618
2619        // "TabBarTheme's labelColor & unselectedLabelColor override TabBar.labelStyle & TabBar.unselectedLabelStyle colors".
2620        #[test]
2621        fn the_theme_label_colors_override_the_tab_bar_label_style_colors() {
2622            test_widgets(|tester| {
2623                let build = |tester: &WidgetTester, tab_bar_theme: Option<TabBarThemeData>| {
2624                    let theme = theme_with(tester, tab_bar_theme, true);
2625                    material_app(
2626                        theme,
2627                        Material::new()
2628                            .child(DefaultTabController::new(
2629                                2,
2630                                TabBar::new(
2631                                    [TAB_1_TEXT, TAB_2_TEXT]
2632                                        .map(|label| Tab::new().text(label).into_widget()),
2633                                )
2634                                .label_style(label_style())
2635                                .unselected_label_style(unselected_label_style()),
2636                            ))
2637                            .into_widget(),
2638                    )
2639                };
2640
2641                // Test tab bar with [TabBar.labelStyle] & [TabBar.unselectedLabelStyle].
2642                let widget = build(tester, None);
2643                tester.pump_widget(widget);
2644                assert_eq!(
2645                    label_colors(tester),
2646                    styled_by(STYLE_COLOR, UNSELECTED_STYLE_COLOR)
2647                );
2648
2649                // Add TabBarTheme with labelColor & unselectedLabelColor.
2650                let widget = build(
2651                    tester,
2652                    Some(
2653                        TabBarThemeData::new()
2654                            .label_color(LABEL_COLOR)
2655                            .unselected_label_color(UNSELECTED_LABEL_COLOR),
2656                    ),
2657                );
2658                tester.pump_widget(widget);
2659                tester.pump_and_settle();
2660                assert_eq!(
2661                    label_colors(tester),
2662                    styled_by(LABEL_COLOR, UNSELECTED_LABEL_COLOR)
2663                );
2664            });
2665        }
2666
2667        fn material2_defaults(secondary: bool) {
2668            test_widgets(|tester| {
2669                // Test default label color and label styles.
2670                let widget = Build {
2671                    secondary_tab_bar: secondary,
2672                    ..Build::default()
2673                }
2674                .build(tester);
2675                tester.pump_widget(widget);
2676
2677                let theme = theme_with(tester, None, false);
2678                let selected_label = text_style(tester, TAB_1_TEXT);
2679                assert_eq!(selected_label.font_family.as_deref(), Some("Roboto"));
2680                assert_eq!(selected_label.font_size, Some(14.0));
2681                assert_eq!(color_of(&selected_label), Some(Colors::WHITE));
2682                let unselected_label = text_style(tester, TAB_2_TEXT);
2683                assert_eq!(unselected_label.font_family.as_deref(), Some("Roboto"));
2684                assert_eq!(unselected_label.font_size, Some(14.0));
2685                assert_eq!(
2686                    color_of(&unselected_label),
2687                    Some(Colors::WHITE.with_alpha(0xB2))
2688                );
2689
2690                // Test default labelPadding.
2691                let (tabs, keys) = sized_tabs();
2692                let widget = Build {
2693                    tabs: Some(tabs),
2694                    is_scrollable: true,
2695                    ..Build::default()
2696                }
2697                .build(tester);
2698                tester.pump_widget(widget);
2699                check_default_label_padding(tester, &keys, 0.0);
2700
2701                // Test default indicator color.
2702                #[allow(deprecated)]
2703                let indicator_color = theme.indicator_color;
2704                let lines = painted_lines(tester, indicator_paint(tester));
2705                assert!(
2706                    lines
2707                        .iter()
2708                        .any(|line| line.color.to_argb32() == indicator_color.to_argb32())
2709                );
2710            });
2711        }
2712
2713        // 'Tab bar defaults (primary)' (Material 2).
2714        #[test]
2715        fn material2_primary_tab_bar_defaults() {
2716            material2_defaults(false);
2717        }
2718
2719        // 'Tab bar defaults (secondary)' (Material 2).
2720        #[test]
2721        fn material2_secondary_tab_bar_defaults() {
2722            material2_defaults(true);
2723        }
2724
2725        // 'TabBarTheme.indicatorSize provides correct tab indicator (primary)' (Material 2).
2726        #[test]
2727        fn material2_the_theme_indicator_size_tab_gives_a_tab_wide_indicator() {
2728            indicator_size_provides_the_indicator(
2729                false,
2730                false,
2731                TabBarIndicatorSize::Tab,
2732                1.0,
2733                199.0,
2734            );
2735        }
2736
2737        // 'TabBarTheme.indicatorSize provides correct tab indicator (secondary)' (Material 2).
2738        #[test]
2739        fn material2_the_theme_indicator_size_label_gives_a_label_wide_secondary_indicator() {
2740            indicator_size_provides_the_indicator(
2741                false,
2742                true,
2743                TabBarIndicatorSize::Label,
2744                66.0,
2745                134.0,
2746            );
2747        }
2748
2749        // 'Material3 - TabBar indicator respects TabBarTheme.indicatorColor'.
2750        #[test]
2751        fn material3_the_indicator_takes_the_theme_indicator_color() {
2752            test_widgets(|tester| {
2753                const TAB_BAR_THEME_INDICATOR_COLOR: Color = Color::new(0xffff0000);
2754                let controller = controller(tester, 4);
2755                let build = |theme: ThemeData| {
2756                    let tabs =
2757                        (0..4).map(|index| Tab::new().text(format!("Tab {index}")).into_widget());
2758                    material_app(
2759                        theme,
2760                        Material::new()
2761                            .child(
2762                                Container::new()
2763                                    .alignment(AlignmentGeometry::TOP_LEFT)
2764                                    .child(TabBar::new(tabs).controller(controller)),
2765                            )
2766                            .into_widget(),
2767                    )
2768                };
2769
2770                let theme = theme_with(tester, None, true);
2771                tester.pump_widget(build.clone()(theme.clone()));
2772                assert!(paints_rrect_color(tester, theme.color_scheme.primary()));
2773
2774                let theme = theme_with(
2775                    tester,
2776                    Some(TabBarThemeData::new().indicator_color(TAB_BAR_THEME_INDICATOR_COLOR)),
2777                    true,
2778                );
2779                tester.pump_widget(build(theme));
2780                tester.pump_and_settle();
2781                assert!(paints_rrect_color(tester, TAB_BAR_THEME_INDICATOR_COLOR));
2782            });
2783        }
2784
2785        // 'Material2 - TabBar indicator respects TabBarTheme.indicatorColor'.
2786        #[test]
2787        fn material2_the_indicator_takes_the_theme_indicator_color() {
2788            test_widgets(|tester| {
2789                const TAB_BAR_THEME_INDICATOR_COLOR: Color = Color::new(0xffffff00);
2790                let controller = controller(tester, 4);
2791                let theme = theme_with(
2792                    tester,
2793                    Some(TabBarThemeData::new().indicator_color(TAB_BAR_THEME_INDICATOR_COLOR)),
2794                    false,
2795                );
2796                let tabs =
2797                    (0..4).map(|index| Tab::new().text(format!("Tab {index}")).into_widget());
2798                tester.pump_widget(material_app(
2799                    theme,
2800                    Material::new()
2801                        .child(
2802                            Container::new()
2803                                .alignment(AlignmentGeometry::TOP_LEFT)
2804                                .child(TabBar::new(tabs).controller(controller)),
2805                        )
2806                        .into_widget(),
2807                ));
2808
2809                let lines = painted_lines(tester, first_render_box::<TabBar>(tester).as_object());
2810                assert!(lines.iter().any(
2811                    |line| line.color.to_argb32() == TAB_BAR_THEME_INDICATOR_COLOR.to_argb32()
2812                ));
2813            });
2814        }
2815
2816        const SELECTED_STATE_COLOR: Color = Color::new(0xff00ff00);
2817        const UNSELECTED_STATE_COLOR: Color = Color::new(0xffff0000);
2818
2819        fn state_label_color() -> WidgetStateColor {
2820            WidgetStateColor::resolve_with(|states| {
2821                if states.contains(&WidgetState::Selected) {
2822                    return SELECTED_STATE_COLOR;
2823                }
2824                UNSELECTED_STATE_COLOR
2825            })
2826        }
2827
2828        /// The selected and unselected tabs' icon and text colors.
2829        fn state_colors(tester: &WidgetTester) -> [Option<Color>; 4] {
2830            [
2831                icon_theme_color(tester, TAB_1_TEXT),
2832                icon_theme_color(tester, TAB_2_TEXT),
2833                color_of(&text_style(tester, TAB_1_TEXT)),
2834                color_of(&text_style(tester, TAB_2_TEXT)),
2835            ]
2836        }
2837
2838        fn colored(selected: Color, unselected: Color) -> [Option<Color>; 4] {
2839            [
2840                Some(selected),
2841                Some(unselected),
2842                Some(selected),
2843                Some(unselected),
2844            ]
2845        }
2846
2847        // 'TabBarTheme.labelColor resolves material states'.
2848        #[test]
2849        fn a_theme_widget_state_label_color_resolves_per_selection() {
2850            test_widgets(|tester| {
2851                let widget = Build {
2852                    tab_bar_theme: Some(TabBarThemeData::new().label_color(state_label_color())),
2853                    ..Build::default()
2854                }
2855                .build(tester);
2856                tester.pump_widget(widget);
2857                assert_eq!(
2858                    state_colors(tester),
2859                    colored(SELECTED_STATE_COLOR, UNSELECTED_STATE_COLOR)
2860                );
2861            });
2862        }
2863
2864        // 'TabBarTheme.labelColor & TabBarTheme.unselectedLabelColor override material state TabBarTheme.labelColor'.
2865        #[test]
2866        fn plain_theme_label_colors_replace_a_widget_state_label_color() {
2867            test_widgets(|tester| {
2868                const SELECTED_COLOR: Color = Color::new(0xff00ffff);
2869                const UNSELECTED_COLOR: Color = Color::new(0xffff12ff);
2870
2871                // Test material state label color.
2872                let widget = Build {
2873                    tab_bar_theme: Some(TabBarThemeData::new().label_color(state_label_color())),
2874                    ..Build::default()
2875                }
2876                .build(tester);
2877                tester.pump_widget(widget);
2878                assert_eq!(
2879                    state_colors(tester),
2880                    colored(SELECTED_STATE_COLOR, UNSELECTED_STATE_COLOR)
2881                );
2882
2883                // Test labelColor & unselectedLabelColor override material state labelColor.
2884                let widget = Build {
2885                    tab_bar_theme: Some(
2886                        TabBarThemeData::new()
2887                            .label_color(SELECTED_COLOR)
2888                            .unselected_label_color(UNSELECTED_COLOR),
2889                    ),
2890                    ..Build::default()
2891                }
2892                .build(tester);
2893                tester.pump_widget(widget);
2894                tester.pump_and_settle();
2895                assert_eq!(
2896                    state_colors(tester),
2897                    colored(SELECTED_COLOR, UNSELECTED_COLOR)
2898                );
2899            });
2900        }
2901
2902        // 'TabBarTheme.textScaler overrides tab label text scale, textScaleFactor = noScaling, 1.75, 2.0'.
2903        #[test]
2904        fn the_theme_text_scaler_overrides_the_ambient_one() {
2905            test_widgets(|tester| {
2906                let build = |tester: &WidgetTester, text_scaler: TextScaler| {
2907                    let theme = theme_with(
2908                        tester,
2909                        Some(TabBarThemeData::new().text_scaler(text_scaler)),
2910                        true,
2911                    );
2912                    material_app(
2913                        theme,
2914                        MediaQuery::new(
2915                            MediaQueryData::new().text_scaler(TextScaler::linear(3.0)),
2916                            DefaultTabController::new(
2917                                2,
2918                                Scaffold::new().app_bar(PreferredSizeWidgetRef::new(
2919                                    AppBar::new().bottom(PreferredSizeWidgetRef::new(TabBar::new(
2920                                        ["Tab 1", "Tab 2"]
2921                                            .map(|label| Tab::new().text(label).into_widget()),
2922                                    ))),
2923                                )),
2924                            ),
2925                        )
2926                        .into_widget(),
2927                    )
2928                };
2929
2930                let widget = build(tester, TextScaler::NO_SCALING);
2931                tester.pump_widget(widget);
2932                assert_eq!(
2933                    tester.get_size(text(tester, "Tab 1")),
2934                    Size::new(70.5, 20.0)
2935                );
2936
2937                let widget = build(tester, TextScaler::linear(1.75));
2938                tester.pump_widget(widget);
2939                tester.pump_and_settle();
2940                assert_eq!(
2941                    tester.get_size(text(tester, "Tab 1")),
2942                    Size::new(123.0, 35.0)
2943                );
2944
2945                let widget = build(tester, TextScaler::linear(2.0));
2946                tester.pump_widget(widget);
2947                tester.pump_and_settle();
2948                assert_eq!(
2949                    tester.get_size(text(tester, "Tab 1")),
2950                    Size::new(140.5, 40.0)
2951                );
2952            });
2953        }
2954
2955        /// Whether the indicator's `CustomPaint` paints `rrect`.
2956        fn indicator_paints_rrect(tester: &WidgetTester, rrect: RRect) -> bool {
2957            waft_rendering::testing::paints(
2958                &tester.painted_ops(first_render_box::<TabBar>(tester).as_object()),
2959                &[waft_rendering::testing::PaintCall::rrect_at(rrect, None)],
2960            )
2961            .is_ok()
2962        }
2963
2964        fn indicator_rrect(left: f64, right: f64, bottom: f64) -> RRect {
2965            RRect::from_ltrb_and_corners(
2966                left,
2967                bottom - 3.0,
2968                right,
2969                bottom,
2970                Radius::circular(3.0),
2971                Radius::circular(3.0),
2972                Radius::ZERO,
2973                Radius::ZERO,
2974            )
2975        }
2976
2977        // 'TabBarTheme indicatorAnimation can customize tab indicator animation'.
2978        #[test]
2979        fn the_theme_indicator_animation_moves_the_indicator_linearly_or_elastically() {
2980            test_widgets(|tester| {
2981                const INDICATOR_WIDTH: f64 = 50.0;
2982                let controller = controller(tester, 4);
2983                let build = |tester: &WidgetTester, indicator_animation: TabIndicatorAnimation| {
2984                    let theme = theme_with(
2985                        tester,
2986                        Some(TabBarThemeData::new().indicator_animation(indicator_animation)),
2987                        true,
2988                    );
2989                    let tabs = (0..4).map(|index| {
2990                        Tab::new()
2991                            .key(waft_foundation::ValueKey::new(index).into())
2992                            .child(SizedBox::new().width(INDICATOR_WIDTH))
2993                            .into_widget()
2994                    });
2995                    material_app(
2996                        theme,
2997                        Material::new()
2998                            .child(
2999                                Container::new()
3000                                    .alignment(AlignmentGeometry::TOP_LEFT)
3001                                    .child(TabBar::new(tabs).controller(controller.clone())),
3002                            )
3003                            .into_widget(),
3004                    )
3005                };
3006
3007                // Test tab indicator animation with TabIndicatorAnimation.linear.
3008                let widget = build(tester, TabIndicatorAnimation::Linear);
3009                tester.pump_widget(widget);
3010
3011                // Idle at tab 0.
3012                assert!(indicator_paints_rrect(
3013                    tester,
3014                    indicator_rrect(75.0, 125.0, 48.0)
3015                ));
3016
3017                // Start moving tab indicator.
3018                controller.set_offset(&mut tester.cell.borrow_mut(), 0.2);
3019                tester.pump();
3020                assert!(indicator_paints_rrect(
3021                    tester,
3022                    indicator_rrect(115.0, 165.0, 48.0)
3023                ));
3024
3025                // Reset tab controller offset.
3026                controller.set_offset(&mut tester.cell.borrow_mut(), 0.0);
3027
3028                // Test tab indicator animation with TabIndicatorAnimation.elastic.
3029                let widget = build(tester, TabIndicatorAnimation::Elastic);
3030                tester.pump_widget(widget);
3031                tester.pump_and_settle();
3032
3033                let height = first_render_box::<TabBar>(tester)
3034                    .size(&tester.cell.borrow())
3035                    .height();
3036                let elastic = |from: Rect, to: Rect, progress: f64| {
3037                    let left_fraction = 1.0 - ((progress * std::f64::consts::PI) / 2.0).cos();
3038                    let right_fraction = ((progress * std::f64::consts::PI) / 2.0).sin();
3039                    let lerp = |a: f64, b: f64, t: f64| a + (b - a) * t;
3040                    indicator_rrect(
3041                        lerp(from.left, to.left, left_fraction),
3042                        lerp(from.right, to.right, right_fraction),
3043                        height,
3044                    )
3045                };
3046
3047                // Idle at tab 0.
3048                let from_rect = Rect::from_ltrb(75.0, 0.0, 125.0, 48.0);
3049                assert!(indicator_paints_rrect(
3050                    tester,
3051                    elastic(from_rect, from_rect, 0.0)
3052                ));
3053
3054                // Start moving tab indicator.
3055                controller.set_offset(&mut tester.cell.borrow_mut(), 0.2);
3056                tester.pump();
3057                let to_rect = Rect::from_ltrb(275.0, 0.0, 325.0, 48.0);
3058                assert!(indicator_paints_rrect(
3059                    tester,
3060                    elastic(from_rect, to_rect, 0.2)
3061                ));
3062            });
3063        }
3064
3065        // 'Tab bar inherits fontFamily from theme when labelStyle and unselectedLabelStyle are specified'.
3066        #[test]
3067        fn the_labels_inherit_the_theme_font_family_unless_their_styles_do_not_inherit() {
3068            test_widgets(|tester| {
3069                const FONT_FAMILY: &str = "TestFont";
3070                let families = |tester: &WidgetTester| {
3071                    [TAB_1_TEXT, TAB_2_TEXT].map(|label| text_style(tester, label).font_family)
3072                };
3073                let some = || [Some(FONT_FAMILY.to_owned()), Some(FONT_FAMILY.to_owned())];
3074
3075                let widget = Build {
3076                    font_family: Some(FONT_FAMILY),
3077                    ..Build::default()
3078                }
3079                .build(tester);
3080                tester.pump_widget(widget);
3081                assert_eq!(families(tester), some());
3082
3083                let widget = Build {
3084                    font_family: Some(FONT_FAMILY),
3085                    local_tab_bar_theme: Some(
3086                        TabBarThemeData::new()
3087                            .label_style(TextStyle::new())
3088                            .unselected_label_style(TextStyle::new()),
3089                    ),
3090                    ..Build::default()
3091                }
3092                .build(tester);
3093                tester.pump_widget(widget);
3094                assert_eq!(families(tester), some());
3095
3096                let widget = Build {
3097                    font_family: Some(FONT_FAMILY),
3098                    label_style: Some(TextStyle::new()),
3099                    unselected_label_style: Some(TextStyle::new()),
3100                    ..Build::default()
3101                }
3102                .build(tester);
3103                tester.pump_widget(widget);
3104                assert_eq!(families(tester), some());
3105
3106                // if inherit is false, the fontFamily should not be applied
3107                let widget = Build {
3108                    font_family: Some(FONT_FAMILY),
3109                    local_tab_bar_theme: Some(
3110                        TabBarThemeData::new()
3111                            .label_style(TextStyle::new().inherit(false))
3112                            .unselected_label_style(TextStyle::new().inherit(false)),
3113                    ),
3114                    ..Build::default()
3115                }
3116                .build(tester);
3117                tester.pump_widget(widget);
3118                assert_eq!(families(tester), [None, None]);
3119
3120                let widget = Build {
3121                    font_family: Some(FONT_FAMILY),
3122                    label_style: Some(TextStyle::new().inherit(false)),
3123                    unselected_label_style: Some(TextStyle::new().inherit(false)),
3124                    ..Build::default()
3125                }
3126                .build(tester);
3127                tester.pump_widget(widget);
3128                assert_eq!(families(tester), [None, None]);
3129            });
3130        }
3131
3132        // 'TabBar inherits splashBorderRadius from theme'.
3133        #[test]
3134        fn the_tab_bar_takes_the_theme_splash_border_radius() {
3135            test_widgets(|tester| {
3136                use crate::material::RenderInkFeatures;
3137
3138                const HOVER_COLOR: Color = Color::new(0xfff44336);
3139                const RADIUS: f64 = 20.0;
3140                tester.pump_widget(
3141                    Material::new()
3142                        .child(
3143                            Localizations::new(
3144                                waft_embedder::Locale::new("en").country_code("US"),
3145                                vec![
3146                                    DefaultMaterialLocalizations::delegate(),
3147                                    DefaultWidgetsLocalizations::delegate(),
3148                                ],
3149                            )
3150                            .child(DefaultTabController::new(
3151                                1,
3152                                TabBarTheme::new()
3153                                    .with_data(TabBarThemeData::new().splash_border_radius(
3154                                        waft_painting::BorderRadius::all(Radius::circular(RADIUS)),
3155                                    ))
3156                                    .child(
3157                                        TabBar::new([Tab::new()
3158                                            .child(waft_widgets::Text::new(""))
3159                                            .into_widget()])
3160                                        .overlay_color(
3161                                            <dyn WidgetStateProperty<Option<Color>>>::from_map(
3162                                                vec![
3163                                                    (
3164                                                        WidgetState::Hovered.into(),
3165                                                        Some(HOVER_COLOR),
3166                                                    ),
3167                                                    (WidgetState::any(), Some(Colors::BLACK54)),
3168                                                ],
3169                                            ),
3170                                        ),
3171                                    ),
3172                            )),
3173                        )
3174                        .into_widget(),
3175                );
3176                let mut gesture = TestPointer::mouse(1, 0);
3177                tester.add_pointer(&mut gesture, Offset::ZERO);
3178                let center = tester.get_rect(only::<Tab>(tester)).center();
3179                tester.move_to(&mut gesture, center, false);
3180                tester.pump_and_settle();
3181
3182                let ink_well = only::<crate::ink_well::InkWell>(tester);
3183                let ink_well_rect = tester.get_rect(ink_well);
3184                let material = {
3185                    let app = tester.cell.borrow();
3186                    Material::of(&app, ink_well)
3187                };
3188                let render = tester
3189                    .all::<RenderInkFeatures>()
3190                    .into_iter()
3191                    .find(|render| render.as_object().id() == material.id())
3192                    .expect("the material's render object");
3193                let mut canvas = waft_embedder::Canvas::new();
3194                render.paint_ink_features(&mut tester.cell.borrow_mut(), &mut canvas, Offset::ZERO);
3195                let expected = RRect::from_rect_and_radius(ink_well_rect, Radius::circular(RADIUS));
3196                let painted = waft_embedder::flattened_ops(&canvas.build())
3197                    .into_iter()
3198                    .any(|op| match op {
3199                        waft_embedder::valo::Op::DrawPath { path, paint, .. } => {
3200                            argb32(paint.color) == HOVER_COLOR.to_argb32()
3201                                && path.as_round_rect().is_some_and(|(rect, radii)| {
3202                                    close(f64::from(rect.x), expected.left, 1e-4)
3203                                        && close(f64::from(rect.y), expected.top, 1e-4)
3204                                        && close(
3205                                            f64::from(rect.x + rect.width),
3206                                            expected.right,
3207                                            1e-4,
3208                                        )
3209                                        && close(
3210                                            f64::from(rect.y + rect.height),
3211                                            expected.bottom,
3212                                            1e-4,
3213                                        )
3214                                        && radii == [[RADIUS as f32; 2]; 4]
3215                                })
3216                        }
3217                        _ => false,
3218                    });
3219                assert!(painted);
3220            });
3221        }
3222    }
3223    // Flutter's "Default TabBarThemeData debugFillProperties".
3224    #[test]
3225    fn a_tab_bar_theme_data_describes_nothing_by_default() {
3226        assert_eq!(
3227            waft_widgets::testing::describe_properties(|properties| {
3228                waft_foundation::Diagnosticable::debug_fill_properties(
3229                    &TabBarThemeData::new(),
3230                    properties,
3231                )
3232            }),
3233            Vec::<String>::new()
3234        );
3235    }
3236}