Skip to main content

waft_material/
input_decorator.rs

1//! Flutter counterpart: material_ui's `input_decorator.dart`, with its part
2//! `generated/input_decorator_defaults_m3.g.dart` in
3//! `crate::generated::input_decorator_defaults_m3`.
4//!
5//! `InputDecorator` builds a `_Decorator` whose `RenderDecoration` lays out the eleven slots;
6//! the `_BorderContainer` paints the border with the gap the render object writes into the
7//! state's `InputBorderGap` during layout. Both defaults (`_InputDecoratorDefaultsM2`/`M3`)
8//! are values filled from the context's theme when the decorator builds.
9
10use std::any::Any;
11use std::fmt::{self, Debug};
12use std::rc::Rc;
13use std::time::Duration;
14
15use waft_animation::{
16    Animatable, Animation, AnimationBehavior, AnimationController, AnimationRef,
17    AnimationWithParent, ColorTween, Curve, CurvedAnimation, Curves, Drive, Tween,
18};
19use waft_embedder::{
20    Brightness, Canvas, Color, Matrix4, Offset, Paint, PaintStyle, SignedDuration, Size,
21    TextBaseline, lerp_double,
22};
23use waft_foundation::{
24    App, ChangeNotifier, ChangeNotifierData, DiagnosticPropertiesBuilder, Diagnosticable,
25    DiagnosticsNode, DiagnosticsProperty, Handle, IntProperty, Listenable, Listener,
26    MergingListenable, OptionRetained, Ref,
27};
28use waft_painting::{
29    AnyBorderSide, AnyColor, AnyTextStyle, BorderSide, ColorProperty, EdgeInsets,
30    EdgeInsetsDirectional, EdgeInsetsGeometry, ShapeBorderRef, TextAlign, TextAlignVertical,
31    TextDirection, TextOverflow, TextStyle,
32};
33use waft_rendering::{
34    AnyRenderBox, AnyRenderObject, BoxConstraints, BoxHitTestResult, BoxParentData,
35    ChildLayoutHelper, ChildLayouter, ContainerLayer, CustomPainter, PaintingContext,
36    PipelineOwner, RenderBox, RenderBoxData, RenderHandle, RenderObject, RenderObjectData,
37    TransformLayer,
38};
39use waft_scheduler::{Ticker, TickerCallback, TickerProviderObject};
40use waft_services::SystemMouseCursors;
41use waft_widgets::{
42    AnimatedDefaultTextStyle, AnimatedOpacity, AnimatedSwitcher, AnimatedSwitcherTransitionBuilder,
43    BuildContext, Builder, Center, ConstrainedBox, CustomPaint, DefaultTextStyle, Directionality,
44    FadeTransition, FractionalTranslation, IconTheme, IconThemeData, IgnorePointer, InheritedTheme,
45    InheritedWidget, IntoWidget, KeyRef, MatrixTransition, MediaQuery, MouseRegion, Padding,
46    RenderObjectWidget, SingleTickerProviderStateMixin, SingleTickerProviderStateMixinData,
47    SizedBox, SlottedContainerRenderObjectData, SlottedContainerRenderObjectMixin,
48    SlottedMultiChildRenderObjectWidget, Stack, State, StateData, StatefulWidget, StatelessWidget,
49    Text, TickerProviderStateMixin, TickerProviderStateMixinData, WidgetRef, WidgetState,
50    WidgetStateColor, WidgetStateProperty, WidgetStatePropertyAll, WidgetStatePropertyRef,
51    WidgetStateTextStyle, WidgetStates,
52};
53
54use crate::button_style::ButtonStyle;
55use crate::colors::Colors;
56use crate::constants::K_MIN_INTERACTIVE_DIMENSION;
57use crate::generated::input_decorator_defaults_m3::InputDecoratorDefaultsM3;
58use crate::icon_button_theme::{IconButtonTheme, IconButtonThemeData};
59use crate::input_border::{
60    InputBorder, InputBorderRef, OutlineInputBorder, UnderlineInputBorder, input_border_of,
61};
62use crate::theme::Theme;
63use crate::theme_data::{ThemeData, VisualDensity};
64use crate::theme_data_getters::DefaultsContext;
65
66// The duration value extracted from:
67// https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/textfield/TextInputLayout.java
68const K_TRANSITION_DURATION: Duration = Duration::from_millis(167);
69fn k_transition_curve() -> Rc<dyn Curve> {
70    Curves::fast_out_slow_in()
71}
72const K_FINAL_LABEL_SCALE: f64 = 0.75;
73
74// From the M3 spec, horizontal padding is 12 pixels for the prefix icon and
75// 16 pixels for the input content.
76// InputDecorator default padding is set to 12 pixels because 16 pixels will move
77// the prefix icon too far.
78// An extra padding should be added for the input content to comply with the 16 pixels padding.
79const K_INPUT_EXTRA_PADDING: f64 = 4.0;
80
81// Padding between the character counter and helper/error text to prevent overlap.
82// Based on Material 3 specification for text fields.
83const K_SUPPORTING_TEXT_COUNTER_PADDING: f64 = 16.0;
84
85/// Dart's `_SupportingTextSize` record.
86#[derive(Clone, Copy, Debug)]
87struct SupportingTextSize {
88    ascent: f64,
89    bottom_height: f64,
90    supporting_text_height: f64,
91}
92
93/// Dart's `_ChildBaselineGetter`.
94type ChildBaselineGetter = fn(&mut App, AnyRenderBox, BoxConstraints) -> f64;
95
96// The default duration for hint fade in/out transitions.
97//
98// Animating hint is not mentioned in the Material specification.
99// The animation is kept for backward compatibility and a short duration
100// is used to mitigate the UX impact.
101const K_HINT_FADE_TRANSITION_DURATION: Duration = Duration::from_millis(20);
102
103// Defines the gap in the InputDecorator's outline border where the
104// floating label will appear.
105struct InputBorderGap {
106    change_notifier: ChangeNotifierData,
107    start: Option<f64>,
108    extent: f64,
109}
110
111impl InputBorderGap {
112    fn new(app: &mut App) -> Ref<InputBorderGap> {
113        app.create(InputBorderGap {
114            change_notifier: ChangeNotifierData::default(),
115            start: None,
116            extent: 0.0,
117        })
118    }
119
120    fn start(self: Handle<Self>, app: &App) -> Option<f64> {
121        app.get(self).start
122    }
123
124    fn set_start(self: Handle<Self>, app: &mut App, value: Option<f64>) {
125        if value != app.get(self).start {
126            app.get_mut(self).start = value;
127            self.notify_listeners(app);
128        }
129    }
130
131    fn extent(self: Handle<Self>, app: &App) -> f64 {
132        app.get(self).extent
133    }
134
135    fn set_extent(self: Handle<Self>, app: &mut App, value: f64) {
136        if value != app.get(self).extent {
137            app.get_mut(self).extent = value;
138            self.notify_listeners(app);
139        }
140    }
141}
142
143impl ChangeNotifier for InputBorderGap {
144    fn change_notifier_data(&self) -> &ChangeNotifierData {
145        &self.change_notifier
146    }
147
148    fn change_notifier_data_mut(&mut self) -> &mut ChangeNotifierData {
149        &mut self.change_notifier
150    }
151}
152
153impl Debug for InputBorderGap {
154    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
155        f.write_str("_InputBorderGap")
156    }
157}
158
159// Used to interpolate between two InputBorders.
160//
161// A value rather than an arena object, as material.rs's `ShapeBorderTween`; the painter holds
162// it in an `Rc`, whose identity is Dart's `Tween ==`.
163#[derive(Clone, Debug)]
164struct InputBorderTween {
165    begin: InputBorderRef,
166    end: InputBorderRef,
167}
168
169impl InputBorderTween {
170    fn new(begin: InputBorderRef, end: InputBorderRef) -> InputBorderTween {
171        InputBorderTween { begin, end }
172    }
173
174    /// Dart's `ShapeBorder.lerp(begin, end, t)! as InputBorder`.
175    fn lerp(&self, t: f64) -> InputBorderRef {
176        let begin = ShapeBorderRef::from(self.begin.clone());
177        let end = ShapeBorderRef::from(self.end.clone());
178        let lerped = ShapeBorderRef::lerp(Some(&begin), Some(&end), t)
179            .expect("lerping two borders gives a border");
180        input_border_of(&*lerped).unwrap_or_else(|| {
181            if t < 0.5 {
182                self.begin.clone()
183            } else {
184                self.end.clone()
185            }
186        })
187    }
188}
189
190/// Dart's `Tween.transform`, which hands back the endpoints themselves at 0 and 1.
191impl Animatable<InputBorderRef> for InputBorderTween {
192    fn transform(&self, _app: &App, t: f64) -> InputBorderRef {
193        if t == 0.0 {
194            return self.begin.clone();
195        }
196        if t == 1.0 {
197            return self.end.clone();
198        }
199        self.lerp(t)
200    }
201}
202
203// Passes the _InputBorderGap parameters along to an InputBorder's paint method.
204struct InputBorderPainter {
205    repaint: Rc<dyn Listenable>,
206    border_animation: AnimationRef<f64>,
207    border: Rc<InputBorderTween>,
208    gap_animation: AnimationRef<f64>,
209    gap: Ref<InputBorderGap>,
210    text_direction: TextDirection,
211    fill_color: Color,
212    hover_color_tween: Ref<ColorTween>,
213    hover_animation: AnimationRef<f64>,
214}
215
216impl InputBorderPainter {
217    fn blended_color(&self, app: &App) -> Color {
218        Color::alpha_blend(
219            self.hover_color_tween
220                .evaluate(app, self.hover_animation.handle())
221                .expect("both colours are given"),
222            self.fill_color,
223        )
224    }
225}
226
227impl CustomPainter for InputBorderPainter {
228    fn repaint(&self) -> Option<&Rc<dyn Listenable>> {
229        Some(&self.repaint)
230    }
231
232    fn paint(&self, app: &mut App, canvas: &mut Canvas, size: Size) {
233        let border_value = self.border.evaluate(app, self.border_animation.handle());
234        let canvas_rect = Offset::ZERO & size;
235        let blended_fill_color = self.blended_color(app);
236        // Dart's `alpha`, deprecated there too.
237        #[allow(deprecated)]
238        let alpha = blended_fill_color.alpha();
239        if alpha > 0 {
240            let paint = Paint {
241                color: blended_fill_color.into(),
242                style: PaintStyle::Fill,
243                ..Paint::default()
244            };
245            if border_value.prefer_paint_interior() {
246                border_value.paint_interior(canvas, canvas_rect, &paint, Some(self.text_direction));
247            } else {
248                let path = border_value.get_outer_path(canvas_rect, Some(self.text_direction));
249                canvas.draw_path(path.as_valo(), path.fill_type, &paint);
250            }
251        }
252
253        InputBorder::paint(
254            &*border_value,
255            canvas,
256            canvas_rect,
257            self.gap.start(app),
258            self.gap.extent(app),
259            self.gap_animation.value(app),
260            Some(self.text_direction),
261        );
262    }
263
264    fn should_repaint(&self, _app: &App, old_delegate: &dyn CustomPainter) -> bool {
265        let Some(old_painter) = old_delegate.as_any().downcast_ref::<InputBorderPainter>() else {
266            return true;
267        };
268        self.border_animation != old_painter.border_animation
269            || self.hover_animation != old_painter.hover_animation
270            || self.gap_animation != old_painter.gap_animation
271            || !Rc::ptr_eq(&self.border, &old_painter.border)
272            || self.gap != old_painter.gap
273            || self.text_direction != old_painter.text_direction
274    }
275
276    fn as_any(&self) -> &dyn Any {
277        self
278    }
279}
280
281impl Debug for InputBorderPainter {
282    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
283        f.write_str("_InputBorderPainter")
284    }
285}
286
287// An analog of AnimatedContainer, which can animate its shaped border, for
288// _InputBorder. This specialized animated container is needed because the
289// _InputBorderGap, which is computed at layout time, is required by the
290// _InputBorder's paint method.
291#[derive(Debug)]
292struct BorderContainer {
293    border: InputBorderRef,
294    gap: Ref<InputBorderGap>,
295    gap_animation: AnimationRef<f64>,
296    fill_color: Color,
297    hover_color: Color,
298    is_hovering: bool,
299}
300
301impl StatefulWidget for BorderContainer {
302    type State = BorderContainerState;
303
304    fn key(&self) -> Option<&KeyRef> {
305        None
306    }
307
308    fn create_state(&self) -> BorderContainerState {
309        BorderContainerState {
310            state: StateData::new(),
311            ticker_provider: TickerProviderStateMixinData::new(),
312            controller: None,
313            hover_color_controller: None,
314            border_animation: None,
315            border: None,
316            hover_animation: None,
317            hover_color_tween: None,
318        }
319    }
320}
321
322/// Dart's `_BorderContainerState`. Its `late` fields are set in `init_state`, because an
323/// arena object needs the [`App`].
324struct BorderContainerState {
325    state: StateData<BorderContainer>,
326    ticker_provider: TickerProviderStateMixinData,
327    controller: Option<Ref<AnimationController>>,
328    hover_color_controller: Option<Ref<AnimationController>>,
329    border_animation: Option<Ref<CurvedAnimation>>,
330    border: Option<Rc<InputBorderTween>>,
331    hover_animation: Option<Ref<CurvedAnimation>>,
332    hover_color_tween: Option<Ref<ColorTween>>,
333}
334
335impl BorderContainerState {
336    const K_HOVER_DURATION: Duration = Duration::from_millis(15);
337
338    fn controller(self: Handle<Self>, app: &App) -> Ref<AnimationController> {
339        app.get(self)
340            .controller
341            .clone()
342            .expect("created in init_state")
343    }
344
345    fn hover_color_controller(self: Handle<Self>, app: &App) -> Ref<AnimationController> {
346        app.get(self)
347            .hover_color_controller
348            .clone()
349            .expect("created in init_state")
350    }
351
352    fn border_animation(self: Handle<Self>, app: &App) -> Ref<CurvedAnimation> {
353        app.get(self)
354            .border_animation
355            .clone()
356            .expect("created in init_state")
357    }
358
359    fn hover_animation(self: Handle<Self>, app: &App) -> Ref<CurvedAnimation> {
360        app.get(self)
361            .hover_animation
362            .clone()
363            .expect("created in init_state")
364    }
365
366    fn hover_color_tween(self: Handle<Self>, app: &App) -> Ref<ColorTween> {
367        app.get(self)
368            .hover_color_tween
369            .clone()
370            .expect("created in init_state")
371    }
372
373    /// Dart's `ColorTween(begin: hoverColor.withAlpha(0), end: hoverColor)`: animate between
374    /// transparent [`BorderContainer::hover_color`] and [`BorderContainer::hover_color`].
375    fn new_hover_color_tween(app: &mut App, hover_color: Color) -> Ref<ColorTween> {
376        ColorTween::new(app, Some(hover_color.with_alpha(0)), Some(hover_color))
377    }
378}
379
380impl TickerProviderStateMixin for BorderContainerState {
381    fn ticker_provider_data(self: Handle<Self>, app: &App) -> &TickerProviderStateMixinData {
382        &app.get(self).ticker_provider
383    }
384
385    fn ticker_provider_data_mut(
386        self: Handle<Self>,
387        app: &mut App,
388    ) -> &mut TickerProviderStateMixinData {
389        &mut app.get_mut(self).ticker_provider
390    }
391}
392
393/// Dart's `vsync: this`.
394impl TickerProviderObject for BorderContainerState {
395    fn create_ticker(self: Handle<Self>, app: &mut App, on_tick: TickerCallback) -> Ref<Ticker> {
396        TickerProviderStateMixin::create_ticker(self, app, on_tick)
397    }
398}
399
400impl State for BorderContainerState {
401    type Widget = BorderContainer;
402    waft_widgets::state_accessors!();
403
404    fn init_state(self: Handle<Self>, app: &mut App) {
405        let widget = self.widget(app);
406        let is_hovering = widget.is_hovering;
407        let border = widget.border.clone();
408        let hover_color = widget.hover_color;
409        let hover_color_controller = AnimationController::new(
410            app,
411            Some(if is_hovering { 1.0 } else { 0.0 }),
412            Some(BorderContainerState::K_HOVER_DURATION),
413            None,
414            0.0,
415            1.0,
416            AnimationBehavior::Normal,
417            self,
418        );
419        let controller = AnimationController::new(
420            app,
421            None,
422            Some(K_TRANSITION_DURATION),
423            None,
424            0.0,
425            1.0,
426            AnimationBehavior::Normal,
427            self,
428        );
429        let border_animation = CurvedAnimation::new(
430            app,
431            controller.erase(),
432            k_transition_curve(),
433            Some(Rc::new(k_transition_curve().flipped())),
434        );
435        let border_tween = Rc::new(InputBorderTween::new(border.clone(), border));
436        let hover_animation =
437            CurvedAnimation::new(app, hover_color_controller.erase(), Curves::linear(), None);
438
439        // Animate between transparent [widget.hoverColor] and [widget.hoverColor].
440        let hover_color_tween = BorderContainerState::new_hover_color_tween(app, hover_color);
441        let state = app.get_mut(self);
442        state.hover_color_controller = Some(hover_color_controller);
443        state.controller = Some(controller);
444        state.border_animation = Some(border_animation);
445        state.border = Some(border_tween);
446        state.hover_animation = Some(hover_animation);
447        state.hover_color_tween = Some(hover_color_tween);
448    }
449
450    fn activate(self: Handle<Self>, app: &mut App) {
451        TickerProviderStateMixin::activate(self, app);
452    }
453
454    fn dispose(self: Handle<Self>, app: &mut App) {
455        let controller = self.controller(app);
456        let hover_color_controller = self.hover_color_controller(app);
457        let border_animation = self.border_animation(app);
458        let hover_animation = self.hover_animation(app);
459        controller.dispose(app);
460        hover_color_controller.dispose(app);
461        border_animation.dispose(app);
462        hover_animation.dispose(app);
463        TickerProviderStateMixin::dispose(self, app);
464    }
465
466    fn did_update_widget(self: Handle<Self>, app: &mut App, old_widget: &BorderContainer) {
467        let widget = self.widget(app);
468        let border = widget.border.clone();
469        let hover_color = widget.hover_color;
470        let is_hovering = widget.is_hovering;
471        if *border != *old_widget.border {
472            app.get_mut(self).border = Some(Rc::new(InputBorderTween::new(
473                old_widget.border.clone(),
474                border,
475            )));
476            let controller = self.controller(app);
477            controller.set_value(app, 0.0);
478            controller.forward(app, None);
479        }
480        if hover_color != old_widget.hover_color {
481            // Animate between transparent [widget.hoverColor] and [widget.hoverColor].
482            let hover_color_tween = BorderContainerState::new_hover_color_tween(app, hover_color);
483            app.get_mut(self).hover_color_tween = Some(hover_color_tween);
484        }
485        if is_hovering != old_widget.is_hovering {
486            let hover_color_controller = self.hover_color_controller(app);
487            if is_hovering {
488                hover_color_controller.forward(app, None);
489            } else {
490                hover_color_controller.reverse(app, None);
491            }
492        }
493    }
494
495    fn build(self: Handle<Self>, app: &mut App, context: BuildContext) -> WidgetRef {
496        let border_animation: AnimationRef<f64> = self.border_animation(app).erase();
497        let hover_color_controller = self.hover_color_controller(app);
498        let widget = self.widget(app);
499        let gap = widget.gap.clone();
500        let gap_animation = widget.gap_animation.clone();
501        let fill_color = widget.fill_color;
502        let border = app.get(self).border.clone().expect("created in init_state");
503        let hover_color_tween = self.hover_color_tween(app);
504        let hover_animation: AnimationRef<f64> = self.hover_animation(app).erase();
505        let text_direction = Directionality::of(app, context);
506        let repaint: Rc<dyn Listenable> = Rc::new(MergingListenable::new(vec![
507            Some(Rc::new(border_animation.clone()) as Rc<dyn Listenable>),
508            Some(Rc::new(gap.clone()) as Rc<dyn Listenable>),
509            Some(Rc::new(hover_color_controller) as Rc<dyn Listenable>),
510        ]));
511        CustomPaint::new()
512            .foreground_painter(InputBorderPainter {
513                repaint,
514                border_animation,
515                border,
516                gap_animation,
517                gap,
518                text_direction,
519                fill_color,
520                hover_color_tween,
521                hover_animation,
522            })
523            .into_widget()
524    }
525}
526
527impl Debug for BorderContainerState {
528    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
529        f.debug_struct("_BorderContainerState")
530            .field("controller", &self.controller)
531            .finish_non_exhaustive()
532    }
533}
534
535// Display the helper and error text. When the error text appears
536// it fades and the helper text fades out. The error text also
537// slides upwards a little when it first appears.
538#[derive(Debug)]
539struct HelperError {
540    text_align: Option<TextAlign>,
541    helper: Option<WidgetRef>,
542    helper_text: Option<String>,
543    helper_style: Option<TextStyle>,
544    helper_max_lines: Option<i32>,
545    error: Option<WidgetRef>,
546    error_text: Option<String>,
547    error_style: Option<TextStyle>,
548    error_max_lines: Option<i32>,
549}
550
551impl StatefulWidget for HelperError {
552    type State = HelperErrorState;
553
554    fn key(&self) -> Option<&KeyRef> {
555        None
556    }
557
558    fn create_state(&self) -> HelperErrorState {
559        HelperErrorState {
560            state: StateData::new(),
561            single_ticker_provider: SingleTickerProviderStateMixinData::default(),
562            controller: None,
563            helper: None,
564            error: None,
565        }
566    }
567}
568
569/// Dart's `_HelperErrorState`.
570struct HelperErrorState {
571    state: StateData<HelperError>,
572    single_ticker_provider: SingleTickerProviderStateMixinData,
573    /// Created in `init_state`, because an arena object needs the [`App`].
574    controller: Option<Ref<AnimationController>>,
575    helper: Option<WidgetRef>,
576    error: Option<WidgetRef>,
577}
578
579impl HelperErrorState {
580    fn controller(self: Handle<Self>, app: &App) -> Ref<AnimationController> {
581        app.get(self)
582            .controller
583            .clone()
584            .expect("created in init_state")
585    }
586
587    /// Dart's `Tween<double>(begin: 1.0, end: 0.0).animate(_controller)`.
588    fn fade_out(self: Handle<Self>, app: &mut App) -> AnimationRef<f64> {
589        let controller = self.controller(app);
590        let tween = Tween::new(app, Some(1.0), Some(0.0));
591        controller.drive(app, tween)
592    }
593
594    fn has_helper(self: Handle<Self>, app: &App) -> bool {
595        let widget = self.widget(app);
596        widget.helper_text.is_some() || widget.helper.is_some()
597    }
598
599    fn has_error(self: Handle<Self>, app: &App) -> bool {
600        let widget = self.widget(app);
601        widget.error_text.is_some() || widget.error.is_some()
602    }
603
604    fn handle_change(self: Handle<Self>, app: &mut App) {
605        self.set_state(app, |_state| {
606            // The _controller's value has changed.
607        });
608    }
609
610    fn build_helper(self: Handle<Self>, app: &mut App) -> WidgetRef {
611        debug_assert!(self.widget(app).helper.is_some() || self.widget(app).helper_text.is_some());
612        let fade_out = self.fade_out(app);
613        let widget = self.widget(app);
614        let child = match &widget.helper {
615            Some(helper) => helper.clone(),
616            None => {
617                let mut text = Text::new(
618                    widget
619                        .helper_text
620                        .clone()
621                        .expect("a helper or its text is given"),
622                )
623                .overflow(TextOverflow::Ellipsis);
624                if let Some(style) = &widget.helper_style {
625                    text = text.style(style.clone());
626                }
627                if let Some(text_align) = widget.text_align {
628                    text = text.text_align(text_align);
629                }
630                if let Some(max_lines) = widget.helper_max_lines {
631                    text = text.max_lines(max_lines);
632                }
633                text.into_widget()
634            }
635        };
636        FadeTransition::new(fade_out).child(child).into_widget()
637    }
638
639    fn build_error(self: Handle<Self>, app: &mut App) -> WidgetRef {
640        debug_assert!(self.widget(app).error.is_some() || self.widget(app).error_text.is_some());
641        let controller = self.controller(app);
642        let widget = self.widget(app);
643        let captured_error_text = widget.error_text.clone();
644        let mut captured_error = widget.error.clone();
645        if let (Some(error), Some(error_style)) = (&captured_error, &widget.error_style) {
646            captured_error =
647                Some(DefaultTextStyle::new(error_style.clone(), error.clone()).into_widget());
648        }
649        let this = self;
650        Builder::new(move |app, context| {
651            // `Semantics(liveRegion:)` waits with accessibility; the read keeps the dependency
652            // on `MediaQuery` Dart registers here.
653            MediaQuery::supports_announce_of(app, context);
654            let child = match &captured_error {
655                Some(error) => error.clone(),
656                None => {
657                    let widget = this.widget(app);
658                    let error_style = widget.error_style.clone();
659                    let text_align = widget.text_align;
660                    let error_max_lines = widget.error_max_lines;
661                    let mut text = Text::new(
662                        captured_error_text
663                            .clone()
664                            .expect("an error or its text is given"),
665                    )
666                    .overflow(TextOverflow::Ellipsis);
667                    if let Some(style) = &error_style {
668                        text = text.style(style.clone());
669                    }
670                    if let Some(text_align) = text_align {
671                        text = text.text_align(text_align);
672                    }
673                    if let Some(max_lines) = error_max_lines {
674                        text = text.max_lines(max_lines);
675                    }
676                    text.into_widget()
677                }
678            };
679            // Dart's `Tween<Offset>(begin: Offset(0.0, -0.25), end: Offset.zero)
680            // .evaluate(_controller.view)`.
681            let begin = Offset::new(0.0, -0.25);
682            let translation = begin + (Offset::ZERO - begin) * controller.value(app);
683            FadeTransition::new(controller.erase())
684                .child(FractionalTranslation::new(translation).child(child))
685                .into_widget()
686        })
687        .into_widget()
688    }
689}
690
691impl SingleTickerProviderStateMixin for HelperErrorState {
692    fn single_ticker_provider_data(
693        self: Handle<Self>,
694        app: &App,
695    ) -> &SingleTickerProviderStateMixinData {
696        &app.get(self).single_ticker_provider
697    }
698
699    fn single_ticker_provider_data_mut(
700        self: Handle<Self>,
701        app: &mut App,
702    ) -> &mut SingleTickerProviderStateMixinData {
703        &mut app.get_mut(self).single_ticker_provider
704    }
705}
706
707/// Dart's `vsync: this`.
708impl TickerProviderObject for HelperErrorState {
709    fn create_ticker(self: Handle<Self>, app: &mut App, on_tick: TickerCallback) -> Ref<Ticker> {
710        SingleTickerProviderStateMixin::create_ticker(self, app, on_tick)
711    }
712}
713
714impl State for HelperErrorState {
715    type Widget = HelperError;
716    waft_widgets::state_accessors!();
717
718    fn init_state(self: Handle<Self>, app: &mut App) {
719        let controller = AnimationController::new(
720            app,
721            None,
722            Some(K_TRANSITION_DURATION),
723            None,
724            0.0,
725            1.0,
726            AnimationBehavior::Normal,
727            self,
728        );
729        app.get_mut(self).controller = Some(controller.clone());
730        if self.has_error(app) {
731            let error = self.build_error(app);
732            app.get_mut(self).error = Some(error);
733            controller.set_value(app, 1.0);
734        } else if self.has_helper(app) {
735            let helper = self.build_helper(app);
736            app.get_mut(self).helper = Some(helper);
737        }
738        controller.add_listener(app, Listener::handle_method(self, Self::handle_change));
739    }
740
741    fn activate(self: Handle<Self>, app: &mut App) {
742        SingleTickerProviderStateMixin::activate(self, app);
743    }
744
745    fn dispose(self: Handle<Self>, app: &mut App) {
746        let controller = self.controller(app);
747        controller.dispose(app);
748        SingleTickerProviderStateMixin::dispose(self, app);
749    }
750
751    fn did_update_widget(self: Handle<Self>, app: &mut App, old: &HelperError) {
752        let widget = self.widget(app);
753        let new_error = widget.error.is_some();
754        let new_error_text = widget.error_text.is_some();
755        let new_helper = widget.helper.is_some();
756        let new_helper_text = widget.helper_text.is_some();
757        let old_error = old.error.is_some();
758        let old_error_text = old.error_text.is_some();
759        let old_helper = old.helper.is_some();
760        let old_helper_text = old.helper_text.is_some();
761
762        let error_state_changed = new_error != old_error;
763        let error_text_state_changed = new_error_text != old_error_text;
764        let helper_state_changed = new_helper != old_helper;
765        let helper_text_state_changed = !new_error_text && new_helper_text != old_helper_text;
766
767        if error_state_changed
768            || error_text_state_changed
769            || helper_state_changed
770            || helper_text_state_changed
771        {
772            let controller = self.controller(app);
773            if new_error || new_error_text {
774                let error = self.build_error(app);
775                app.get_mut(self).error = Some(error);
776                controller.forward(app, None);
777            } else if new_helper || new_helper_text {
778                let helper = self.build_helper(app);
779                app.get_mut(self).helper = Some(helper);
780                controller.reverse(app, None);
781            } else {
782                controller.reverse(app, None);
783            }
784        }
785    }
786
787    fn build(self: Handle<Self>, app: &mut App, _context: BuildContext) -> WidgetRef {
788        // If the height of this widget and the counter are zero ("empty") at
789        // layout time, no space is allocated for the supportingText.
790        let empty = || SizedBox::shrink().into_widget();
791
792        let controller = self.controller(app);
793        if controller.is_dismissed(app) {
794            app.get_mut(self).error = None;
795            if self.has_helper(app) {
796                let helper = self.build_helper(app);
797                app.get_mut(self).helper = Some(helper.clone());
798                return helper;
799            } else {
800                app.get_mut(self).helper = None;
801                return empty();
802            }
803        }
804
805        if controller.is_completed(app) {
806            app.get_mut(self).helper = None;
807            if self.has_error(app) {
808                let error = self.build_error(app);
809                app.get_mut(self).error = Some(error.clone());
810                return error;
811            } else {
812                app.get_mut(self).error = None;
813                return empty();
814            }
815        }
816
817        if app.get(self).helper.is_none() && self.has_error(app) {
818            return self.build_error(app);
819        }
820
821        if app.get(self).error.is_none() && self.has_helper(app) {
822            return self.build_helper(app);
823        }
824
825        if self.has_error(app) {
826            let fade_out = self.fade_out(app);
827            let mut helper_transition = FadeTransition::new(fade_out);
828            if let Some(helper) = app.get(self).helper.clone() {
829                helper_transition = helper_transition.child(helper);
830            }
831            let error = self.build_error(app);
832            return Stack::new()
833                .children([helper_transition.into_widget(), error])
834                .into_widget();
835        }
836
837        if self.has_helper(app) {
838            let helper = self.build_helper(app);
839            let mut error_transition = FadeTransition::new(controller.erase());
840            if let Some(error) = app.get(self).error.clone() {
841                error_transition = error_transition.child(error);
842            }
843            return Stack::new()
844                .children([helper, error_transition.into_widget()])
845                .into_widget();
846        }
847
848        empty()
849    }
850}
851
852impl Debug for HelperErrorState {
853    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
854        f.debug_struct("_HelperErrorState")
855            .field("controller", &self.controller)
856            .finish_non_exhaustive()
857    }
858}
859
860/// Defines **how** the floating label should behave.
861///
862/// See also:
863///
864///  * `InputDecoration::floating_label_behavior` which defines the behavior for
865///    `InputDecoration::label` or `InputDecoration::label_text`.
866///  * [`FloatingLabelAlignment`] which defines **where** the floating label
867///    should displayed.
868#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
869pub enum FloatingLabelBehavior {
870    /// The label will always be positioned within the content, or hidden.
871    Never,
872
873    /// The label will float when the input is focused, or has content.
874    Auto,
875
876    /// The label will always float above the content.
877    Always,
878}
879
880/// Defines **where** the floating label should be displayed within an
881/// `InputDecorator`.
882///
883/// See also:
884///
885///  * `InputDecoration::floating_label_alignment` which defines the alignment for
886///    `InputDecoration::label` or `InputDecoration::label_text`.
887///  * [`FloatingLabelBehavior`] which defines **how** the floating label should
888///    behave.
889#[derive(Clone, Copy, PartialEq)]
890pub struct FloatingLabelAlignment {
891    // -1 denotes start, 0 denotes center, and 1 denotes end.
892    x: f64,
893}
894
895impl FloatingLabelAlignment {
896    const fn private(x: f64) -> FloatingLabelAlignment {
897        assert!(x >= -1.0 && x <= 1.0);
898        FloatingLabelAlignment { x }
899    }
900
901    /// Align the floating label on the leading edge of the `InputDecorator`.
902    ///
903    /// For left-to-right text ([`TextDirection::Ltr`]), this is the left edge.
904    ///
905    /// For right-to-left text ([`TextDirection::Rtl`]), this is the right edge.
906    pub const START: FloatingLabelAlignment = FloatingLabelAlignment::private(-1.0);
907
908    /// Aligns the floating label to the center of an `InputDecorator`.
909    pub const CENTER: FloatingLabelAlignment = FloatingLabelAlignment::private(0.0);
910
911    fn stringify(x: f64) -> String {
912        if x == -1.0 {
913            "FloatingLabelAlignment.start".to_owned()
914        } else if x == 0.0 {
915            "FloatingLabelAlignment.center".to_owned()
916        } else {
917            format!("FloatingLabelAlignment(x: {x:.1})")
918        }
919    }
920}
921
922impl Debug for FloatingLabelAlignment {
923    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
924        f.write_str(&FloatingLabelAlignment::stringify(self.x))
925    }
926}
927
928// Identifies the children of a _RenderDecorationElement.
929#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
930enum DecorationSlot {
931    Icon,
932    Input,
933    Label,
934    Hint,
935    Prefix,
936    Suffix,
937    PrefixIcon,
938    SuffixIcon,
939    HelperError,
940    Counter,
941    Container,
942}
943
944impl DecorationSlot {
945    /// Dart's `_DecorationSlot.values`.
946    const VALUES: [DecorationSlot; 11] = [
947        DecorationSlot::Icon,
948        DecorationSlot::Input,
949        DecorationSlot::Label,
950        DecorationSlot::Hint,
951        DecorationSlot::Prefix,
952        DecorationSlot::Suffix,
953        DecorationSlot::PrefixIcon,
954        DecorationSlot::SuffixIcon,
955        DecorationSlot::HelperError,
956        DecorationSlot::Counter,
957        DecorationSlot::Container,
958    ];
959}
960
961/// Dart's `identical` on two optional widgets.
962fn same_widget(a: &Option<WidgetRef>, b: &Option<WidgetRef>) -> bool {
963    match (a, b) {
964        (None, None) => true,
965        (Some(a), Some(b)) => Rc::ptr_eq(a, b),
966        _ => false,
967    }
968}
969
970// An analog of InputDecoration for the _Decorator widget.
971#[derive(Clone, Debug)]
972struct Decoration {
973    content_padding: EdgeInsetsDirectional,
974    is_collapsed: bool,
975    floating_label_height: f64,
976    floating_label_progress: f64,
977    floating_label_alignment: FloatingLabelAlignment,
978    border: InputBorderRef,
979    border_gap: Ref<InputBorderGap>,
980    align_label_with_hint: bool,
981    is_dense: Option<bool>,
982    is_empty: bool,
983    visual_density: VisualDensity,
984    input_gap: f64,
985    maintain_hint_size: bool,
986    maintain_label_size: bool,
987    icon: Option<WidgetRef>,
988    input: Option<WidgetRef>,
989    label: Option<WidgetRef>,
990    hint: Option<WidgetRef>,
991    prefix: Option<WidgetRef>,
992    suffix: Option<WidgetRef>,
993    prefix_icon: Option<WidgetRef>,
994    suffix_icon: Option<WidgetRef>,
995    helper_error: Option<WidgetRef>,
996    counter: Option<WidgetRef>,
997    container: Option<WidgetRef>,
998    supporting_text_padding: Option<EdgeInsetsDirectional>,
999}
1000
1001impl PartialEq for Decoration {
1002    // Dart's `==` compares the widgets by their `==`, which is identity.
1003    fn eq(&self, other: &Decoration) -> bool {
1004        other.content_padding == self.content_padding
1005            && other.is_collapsed == self.is_collapsed
1006            && other.floating_label_height == self.floating_label_height
1007            && other.floating_label_progress == self.floating_label_progress
1008            && other.floating_label_alignment == self.floating_label_alignment
1009            && *other.border == *self.border
1010            && other.border_gap == self.border_gap
1011            && other.align_label_with_hint == self.align_label_with_hint
1012            && other.is_dense == self.is_dense
1013            && other.is_empty == self.is_empty
1014            && other.visual_density == self.visual_density
1015            && other.input_gap == self.input_gap
1016            && other.maintain_hint_size == self.maintain_hint_size
1017            && other.maintain_label_size == self.maintain_label_size
1018            && same_widget(&other.icon, &self.icon)
1019            && same_widget(&other.input, &self.input)
1020            && same_widget(&other.label, &self.label)
1021            && same_widget(&other.hint, &self.hint)
1022            && same_widget(&other.prefix, &self.prefix)
1023            && same_widget(&other.suffix, &self.suffix)
1024            && same_widget(&other.prefix_icon, &self.prefix_icon)
1025            && same_widget(&other.suffix_icon, &self.suffix_icon)
1026            && same_widget(&other.helper_error, &self.helper_error)
1027            && same_widget(&other.counter, &self.counter)
1028            && same_widget(&other.container, &self.container)
1029            && other.supporting_text_padding == self.supporting_text_padding
1030    }
1031}
1032
1033// A container for the layout values computed by _RenderDecoration._layout.
1034// These values are used by _RenderDecoration.performLayout to position
1035// all of the renderer children of a _RenderDecoration.
1036#[derive(Clone, Copy, Debug)]
1037struct RenderDecorationLayout {
1038    input_constraints: BoxConstraints,
1039    baseline: f64,
1040    container_height: f64,
1041    supporting_text_size: Option<SupportingTextSize>,
1042    size: Size,
1043}
1044
1045// The workhorse: layout and paint a _Decorator widget's _Decoration.
1046struct RenderDecoration {
1047    render_object: RenderObjectData,
1048    render_box: RenderBoxData,
1049    slotted: SlottedContainerRenderObjectData<DecorationSlot, AnyRenderBox>,
1050    decoration: Decoration,
1051    text_direction: TextDirection,
1052    text_baseline: TextBaseline,
1053    text_align_vertical: Option<TextAlignVertical>,
1054    is_focused: bool,
1055    expands: bool,
1056    material3: bool,
1057    // Records where the label was painted.
1058    label_transform: Option<Matrix4>,
1059}
1060
1061/// The getter and the setter of one of `_RenderDecoration`'s properties, the setter marking
1062/// the decoration as needing layout when the value changes. Dart declares both for each
1063/// property; `textBaseline`'s getter and `material3`'s setter have no caller there either.
1064macro_rules! render_decoration_property {
1065    ($($field:ident, $setter:ident: $ty:ty;)*) => {
1066        $(
1067            #[allow(dead_code)]
1068            fn $field(self: RenderHandle<Self>, app: &App) -> $ty {
1069                self.get(app).$field
1070            }
1071
1072            #[allow(dead_code)]
1073            fn $setter(self: RenderHandle<Self>, app: &mut App, value: $ty) {
1074                if self.get(app).$field == value {
1075                    return;
1076                }
1077                self.get_mut(app).$field = value;
1078                self.mark_needs_layout(app);
1079            }
1080        )*
1081    };
1082}
1083
1084impl RenderDecoration {
1085    #[allow(clippy::too_many_arguments)]
1086    fn new(
1087        app: &mut App,
1088        decoration: Decoration,
1089        text_direction: TextDirection,
1090        text_baseline: TextBaseline,
1091        is_focused: bool,
1092        expands: bool,
1093        material3: bool,
1094        text_align_vertical: Option<TextAlignVertical>,
1095    ) -> RenderHandle<RenderDecoration> {
1096        RenderHandle::new_box(
1097            app,
1098            RenderDecoration {
1099                render_object: RenderObjectData::new(),
1100                render_box: RenderBoxData::new(),
1101                slotted: SlottedContainerRenderObjectData::new(),
1102                decoration,
1103                text_direction,
1104                text_baseline,
1105                text_align_vertical,
1106                is_focused,
1107                expands,
1108                material3,
1109                label_transform: None,
1110            },
1111        )
1112    }
1113
1114    // TODO(bleroux): consider defining this value as a Material token and making it
1115    // configurable by InputDecorationThemeData.
1116    fn supporting_text_gap(self: RenderHandle<Self>, app: &App) -> f64 {
1117        if self.material3(app) { 4.0 } else { 8.0 }
1118    }
1119
1120    fn prefix_to_input_gap(self: RenderHandle<Self>, app: &App) -> f64 {
1121        if self.material3(app) { 4.0 } else { 0.0 }
1122    }
1123
1124    fn input_to_suffix_gap(self: RenderHandle<Self>, app: &App) -> f64 {
1125        if self.material3(app) { 4.0 } else { 0.0 }
1126    }
1127
1128    fn icon(self: RenderHandle<Self>, app: &App) -> Option<AnyRenderBox> {
1129        self.child_for_slot(app, &DecorationSlot::Icon)
1130    }
1131
1132    fn input(self: RenderHandle<Self>, app: &App) -> Option<AnyRenderBox> {
1133        self.child_for_slot(app, &DecorationSlot::Input)
1134    }
1135
1136    fn label(self: RenderHandle<Self>, app: &App) -> Option<AnyRenderBox> {
1137        self.child_for_slot(app, &DecorationSlot::Label)
1138    }
1139
1140    fn hint(self: RenderHandle<Self>, app: &App) -> Option<AnyRenderBox> {
1141        self.child_for_slot(app, &DecorationSlot::Hint)
1142    }
1143
1144    fn prefix(self: RenderHandle<Self>, app: &App) -> Option<AnyRenderBox> {
1145        self.child_for_slot(app, &DecorationSlot::Prefix)
1146    }
1147
1148    fn suffix(self: RenderHandle<Self>, app: &App) -> Option<AnyRenderBox> {
1149        self.child_for_slot(app, &DecorationSlot::Suffix)
1150    }
1151
1152    fn prefix_icon(self: RenderHandle<Self>, app: &App) -> Option<AnyRenderBox> {
1153        self.child_for_slot(app, &DecorationSlot::PrefixIcon)
1154    }
1155
1156    fn suffix_icon(self: RenderHandle<Self>, app: &App) -> Option<AnyRenderBox> {
1157        self.child_for_slot(app, &DecorationSlot::SuffixIcon)
1158    }
1159
1160    fn helper_error(self: RenderHandle<Self>, app: &App) -> AnyRenderBox {
1161        self.child_for_slot(app, &DecorationSlot::HelperError)
1162            .expect("an input decorator always has a helper and error child")
1163    }
1164
1165    fn counter(self: RenderHandle<Self>, app: &App) -> Option<AnyRenderBox> {
1166        self.child_for_slot(app, &DecorationSlot::Counter)
1167    }
1168
1169    /// The decoration's "container", the area [`InputDecorator::container_of`] answers.
1170    fn container(self: RenderHandle<Self>, app: &App) -> Option<AnyRenderBox> {
1171        self.child_for_slot(app, &DecorationSlot::Container)
1172    }
1173
1174    fn decoration(self: RenderHandle<Self>, app: &App) -> &Decoration {
1175        &self.get(app).decoration
1176    }
1177
1178    fn set_decoration(self: RenderHandle<Self>, app: &mut App, value: Decoration) {
1179        if self.get(app).decoration == value {
1180            return;
1181        }
1182        self.get_mut(app).decoration = value;
1183        self.mark_needs_layout(app);
1184    }
1185
1186    render_decoration_property! {
1187        text_direction, set_text_direction: TextDirection;
1188        text_baseline, set_text_baseline: TextBaseline;
1189        expands, set_expands: bool;
1190        material3, set_material3: bool;
1191    }
1192
1193    fn default_text_align_vertical(self: RenderHandle<Self>, app: &App) -> TextAlignVertical {
1194        if self.is_outline_aligned(app) {
1195            TextAlignVertical::CENTER
1196        } else {
1197            TextAlignVertical::TOP
1198        }
1199    }
1200
1201    fn text_align_vertical(self: RenderHandle<Self>, app: &App) -> TextAlignVertical {
1202        self.get(app)
1203            .text_align_vertical
1204            .unwrap_or_else(|| self.default_text_align_vertical(app))
1205    }
1206
1207    fn set_text_align_vertical(
1208        self: RenderHandle<Self>,
1209        app: &mut App,
1210        value: Option<TextAlignVertical>,
1211    ) {
1212        if self.get(app).text_align_vertical.map(|value| value.y) == value.map(|value| value.y) {
1213            return;
1214        }
1215        // No need to relayout if the effective value is still the same.
1216        if self.text_align_vertical(app).y
1217            == value.map_or_else(|| self.default_text_align_vertical(app).y, |value| value.y)
1218        {
1219            self.get_mut(app).text_align_vertical = value;
1220            return;
1221        }
1222        self.get_mut(app).text_align_vertical = value;
1223        self.mark_needs_layout(app);
1224    }
1225
1226    fn set_is_focused(self: RenderHandle<Self>, app: &mut App, value: bool) {
1227        if self.get(app).is_focused == value {
1228            return;
1229        }
1230        self.get_mut(app).is_focused = value;
1231    }
1232
1233    // Indicates that the decoration should be aligned to accommodate an outline
1234    // border.
1235    fn is_outline_aligned(self: RenderHandle<Self>, app: &App) -> bool {
1236        let decoration = self.decoration(app);
1237        !decoration.is_collapsed && decoration.border.is_outline()
1238    }
1239
1240    fn density_offset(self: RenderHandle<Self>, app: &App) -> Offset {
1241        self.decoration(app).visual_density.base_size_adjustment()
1242    }
1243
1244    fn min_width(app: &mut App, r#box: Option<AnyRenderBox>, height: f64) -> f64 {
1245        r#box.map_or(0.0, |r#box| r#box.get_min_intrinsic_width(app, height))
1246    }
1247
1248    fn max_width(app: &mut App, r#box: Option<AnyRenderBox>, height: f64) -> f64 {
1249        r#box.map_or(0.0, |r#box| r#box.get_max_intrinsic_width(app, height))
1250    }
1251
1252    fn min_height(app: &mut App, r#box: Option<AnyRenderBox>, width: f64) -> f64 {
1253        r#box.map_or(0.0, |r#box| r#box.get_min_intrinsic_height(app, width))
1254    }
1255
1256    fn box_size(app: &App, r#box: Option<AnyRenderBox>) -> Size {
1257        r#box.map_or(Size::ZERO, |r#box| r#box.size(app))
1258    }
1259
1260    fn get_baseline(app: &mut App, r#box: AnyRenderBox, box_constraints: BoxConstraints) -> f64 {
1261        ChildLayoutHelper::get_baseline(app, r#box, box_constraints, TextBaseline::Alphabetic)
1262            .unwrap_or_else(|| r#box.size(app).height())
1263    }
1264
1265    fn get_dry_baseline(
1266        app: &mut App,
1267        r#box: AnyRenderBox,
1268        box_constraints: BoxConstraints,
1269    ) -> f64 {
1270        ChildLayoutHelper::get_dry_baseline(app, r#box, box_constraints, TextBaseline::Alphabetic)
1271            .unwrap_or_else(|| {
1272                ChildLayoutHelper::dry_layout_child(app, r#box, box_constraints).height()
1273            })
1274    }
1275
1276    fn box_parent_data(app: &App, r#box: AnyRenderBox) -> &BoxParentData {
1277        r#box.box_parent_data(app)
1278    }
1279
1280    fn set_offset(app: &mut App, r#box: AnyRenderBox, offset: Offset) {
1281        r#box.parent_data_of_mut::<BoxParentData>(app).offset = offset;
1282    }
1283
1284    fn content_padding(self: RenderHandle<Self>, app: &App) -> EdgeInsetsDirectional {
1285        self.decoration(app).content_padding
1286    }
1287
1288    fn supporting_text_padding(
1289        self: RenderHandle<Self>,
1290        app: &App,
1291    ) -> Option<EdgeInsetsDirectional> {
1292        self.decoration(app).supporting_text_padding
1293    }
1294
1295    fn compute_supporting_text_sizes(
1296        self: RenderHandle<Self>,
1297        app: &mut App,
1298        constraints: BoxConstraints,
1299        layout_child: ChildLayouter,
1300        get_baseline: ChildBaselineGetter,
1301    ) -> Option<SupportingTextSize> {
1302        let counter = self.counter(app);
1303        let (counter_size, counter_ascent) = match counter {
1304            Some(r#box) => (
1305                layout_child(app, r#box, constraints),
1306                get_baseline(app, r#box, constraints),
1307            ),
1308            None => (Size::ZERO, 0.0),
1309        };
1310
1311        // Only add padding when counter is present (maxLength is used).
1312        let counter_padding = if counter.is_some() {
1313            K_SUPPORTING_TEXT_COUNTER_PADDING
1314        } else {
1315            0.0
1316        };
1317        let helper_error_constraints = constraints.deflate(EdgeInsetsGeometry::only(
1318            counter_size.width() + counter_padding,
1319            0.0,
1320            0.0,
1321            0.0,
1322        ));
1323        let helper_error = self.helper_error(app);
1324        let helper_error_height =
1325            layout_child(app, helper_error, helper_error_constraints).height();
1326
1327        if helper_error_height == 0.0 && counter_size.height() == 0.0 {
1328            return None;
1329        }
1330
1331        // TODO(LongCatIsLooong): the bottomHeight expression doesn't make much sense.
1332        // Use the real descent and make sure the supportingText line box is tall enough for both children.
1333        // See https://github.com/flutter/flutter/issues/13715
1334
1335        // The vertical padding around the row containing the helper, error, and counter widgets.
1336        // Defaults to `supportingTextGap` at the top and 0.0 at the bottom when `supportingTextPadding` is null.
1337        let supporting_text_padding = self.supporting_text_padding(app);
1338        let top_padding = supporting_text_padding
1339            .map_or_else(|| self.supporting_text_gap(app), |padding| padding.top);
1340        let bottom_padding = supporting_text_padding.map_or(0.0, |padding| padding.bottom);
1341        let ascent = counter_ascent.max(get_baseline(app, helper_error, helper_error_constraints))
1342            + top_padding;
1343        let bottom_height =
1344            counter_ascent.max(helper_error_height) + (top_padding + bottom_padding);
1345        let supporting_text_height =
1346            counter_size.height().max(helper_error_height) + (top_padding + bottom_padding);
1347        Some(SupportingTextSize {
1348            ascent,
1349            bottom_height,
1350            supporting_text_height,
1351        })
1352    }
1353
1354    // Returns a value used by performLayout to position all of the renderers.
1355    // This method applies layout to all of the renderers except the container.
1356    // For convenience, the container is laid out in performLayout().
1357    fn layout(
1358        self: RenderHandle<Self>,
1359        app: &mut App,
1360        constraints: BoxConstraints,
1361        layout_child: ChildLayouter,
1362        get_baseline: ChildBaselineGetter,
1363    ) -> RenderDecorationLayout {
1364        debug_assert!(
1365            constraints.max_width < f64::INFINITY,
1366            "An InputDecorator, which is typically created by a TextField, cannot \
1367             have an unbounded width.\n\
1368             This happens when the parent widget does not provide a finite width \
1369             constraint. For example, if the InputDecorator is contained by a Row, \
1370             then its width must be constrained. An Expanded widget or a SizedBox \
1371             can be used to constrain the width of the InputDecorator or the \
1372             TextField that contains it."
1373        );
1374
1375        let box_constraints = constraints.loosen();
1376        let decoration = self.decoration(app).clone();
1377        let content_padding = self.content_padding(app);
1378        let supporting_text_padding = decoration.supporting_text_padding;
1379
1380        // Layout all the widgets used by InputDecorator
1381        let icon = self.icon(app);
1382        let icon_width = match icon {
1383            None => 0.0,
1384            Some(icon) => layout_child(app, icon, box_constraints).width(),
1385        };
1386        let container_constraints =
1387            box_constraints.deflate(EdgeInsetsGeometry::only(icon_width, 0.0, 0.0, 0.0));
1388        let content_constraints = container_constraints.deflate(EdgeInsetsGeometry::directional(
1389            content_padding.start + decoration.input_gap,
1390            0.0,
1391            content_padding.end + decoration.input_gap,
1392            0.0,
1393        ));
1394        let supporting_text_constraints =
1395            container_constraints.deflate(EdgeInsetsGeometry::directional(
1396                supporting_text_padding.map_or(content_padding.start, |padding| padding.start)
1397                    + decoration.input_gap,
1398                0.0,
1399                supporting_text_padding.map_or(content_padding.end, |padding| padding.end)
1400                    + decoration.input_gap,
1401                0.0,
1402            ));
1403
1404        // The helper or error text can occupy the full width less the space
1405        // occupied by the icon and counter.
1406        let supporting_text_size = self.compute_supporting_text_sizes(
1407            app,
1408            supporting_text_constraints,
1409            layout_child,
1410            get_baseline,
1411        );
1412
1413        let prefix_icon = self.prefix_icon(app);
1414        let suffix_icon = self.suffix_icon(app);
1415        let prefix_icon_size = match prefix_icon {
1416            None => Size::ZERO,
1417            Some(prefix_icon) => layout_child(app, prefix_icon, container_constraints),
1418        };
1419        let suffix_icon_size = match suffix_icon {
1420            None => Size::ZERO,
1421            Some(suffix_icon) => layout_child(app, suffix_icon, container_constraints),
1422        };
1423        let prefix = self.prefix(app);
1424        let suffix = self.suffix(app);
1425        let prefix_size = match prefix {
1426            None => Size::ZERO,
1427            Some(prefix) => layout_child(app, prefix, content_constraints),
1428        };
1429        let suffix_size = match suffix {
1430            None => Size::ZERO,
1431            Some(suffix) => layout_child(app, suffix, content_constraints),
1432        };
1433
1434        let accessory_horizontal_insets = EdgeInsetsDirectional::only(
1435            icon_width
1436                + prefix_size.width()
1437                + if prefix_icon.is_none() {
1438                    content_padding.start + decoration.input_gap
1439                } else {
1440                    prefix_icon_size.width() + self.prefix_to_input_gap(app)
1441                },
1442            0.0,
1443            suffix_size.width()
1444                + if suffix_icon.is_none() {
1445                    content_padding.end + decoration.input_gap
1446                } else {
1447                    suffix_icon_size.width() + self.input_to_suffix_gap(app)
1448                },
1449            0.0,
1450        );
1451
1452        let input_width = (constraints.max_width
1453            - (accessory_horizontal_insets.start + accessory_horizontal_insets.end))
1454            .max(0.0);
1455        let label = self.label(app);
1456        let top_height = if let Some(label) = label {
1457            let suffix_icon_space = if decoration.border.is_outline() {
1458                lerp_double(
1459                    Some(suffix_icon_size.width()),
1460                    Some(content_padding.end),
1461                    decoration.floating_label_progress,
1462                )
1463                .expect("both ends are given")
1464            } else {
1465                suffix_icon_size.width()
1466            };
1467            let label_width = (constraints.max_width
1468                - (decoration.input_gap * 2.0
1469                    + icon_width
1470                    + if prefix_icon.is_none() {
1471                        content_padding.start
1472                    } else {
1473                        prefix_icon_size.width()
1474                    }
1475                    + if suffix_icon.is_none() {
1476                        content_padding.end
1477                    } else {
1478                        suffix_icon_space
1479                    }))
1480            .max(0.0);
1481
1482            // Increase the available width for the label when it is scaled down.
1483            let inverted_label_scale = lerp_double(
1484                Some(1.00),
1485                Some(1.0 / K_FINAL_LABEL_SCALE),
1486                decoration.floating_label_progress,
1487            )
1488            .expect("both ends are given");
1489            let label_constraints = BoxConstraints {
1490                max_width: label_width * inverted_label_scale,
1491                ..box_constraints
1492            };
1493            layout_child(app, label, label_constraints);
1494
1495            let label_height = decoration.floating_label_height;
1496            if decoration.border.is_outline() {
1497                (label_height - get_baseline(app, label, label_constraints)).max(0.0)
1498            } else {
1499                label_height
1500            }
1501        } else {
1502            0.0
1503        };
1504
1505        // The height of the input needs to accommodate label above and counter and
1506        // helperError below, when they exist.
1507        let bottom_height = supporting_text_size.map_or(0.0, |size| size.bottom_height);
1508        let density_offset = self.density_offset(app);
1509        let input_constraints = box_constraints
1510            .deflate(EdgeInsetsGeometry::only(
1511                0.0,
1512                (content_padding.top + content_padding.bottom)
1513                    + top_height
1514                    + bottom_height
1515                    + density_offset.dy(),
1516                0.0,
1517                0.0,
1518            ))
1519            .tighten(Some(input_width), None);
1520
1521        let input = self.input(app);
1522        let hint = self.hint(app);
1523        let input_size = match input {
1524            None => Size::ZERO,
1525            Some(input) => layout_child(app, input, input_constraints),
1526        };
1527        let hint_size = match hint {
1528            None => Size::ZERO,
1529            Some(hint) => layout_child(app, hint, box_constraints.tighten(Some(input_width), None)),
1530        };
1531        let input_baseline = match input {
1532            None => 0.0,
1533            Some(input) => get_baseline(app, input, input_constraints),
1534        };
1535        let hint_baseline = match hint {
1536            None => 0.0,
1537            Some(hint) => get_baseline(app, hint, box_constraints.tighten(Some(input_width), None)),
1538        };
1539
1540        // The field can be occupied by a hint or by the input itself.
1541        let input_height = (if decoration.is_empty || decoration.maintain_hint_size {
1542            hint_size.height()
1543        } else {
1544            0.0
1545        })
1546        .max(input_size.height());
1547        let input_internal_baseline = input_baseline.max(hint_baseline);
1548
1549        let prefix_baseline = match prefix {
1550            None => 0.0,
1551            Some(prefix) => get_baseline(app, prefix, content_constraints),
1552        };
1553        let suffix_baseline = match suffix {
1554            None => 0.0,
1555            Some(suffix) => get_baseline(app, suffix, content_constraints),
1556        };
1557
1558        // Calculate the amount that prefix/suffix affects height above and below
1559        // the input.
1560        let fix_height = prefix_baseline.max(suffix_baseline);
1561        let fix_above_input = (fix_height - input_internal_baseline).max(0.0);
1562        let fix_below_baseline =
1563            (prefix_size.height() - prefix_baseline).max(suffix_size.height() - suffix_baseline);
1564        // TODO(justinmc): fixBelowInput should have no effect when there is no
1565        // prefix/suffix below the input.
1566        // https://github.com/flutter/flutter/issues/66050
1567        let fix_below_input =
1568            (fix_below_baseline - (input_height - input_internal_baseline)).max(0.0);
1569
1570        // Calculate the height of the input text container.
1571        let fix_icon_height = prefix_icon_size.height().max(suffix_icon_size.height());
1572        let content_height = fix_icon_height.max(
1573            top_height
1574                + content_padding.top
1575                + fix_above_input
1576                + input_height
1577                + fix_below_input
1578                + content_padding.bottom
1579                + density_offset.dy(),
1580        );
1581        let expands = self.expands(app);
1582        let min_container_height = if decoration.is_dense.expect("applied from the theme")
1583            || decoration.is_collapsed
1584            || expands
1585        {
1586            input_height
1587        } else {
1588            K_MIN_INTERACTIVE_DIMENSION
1589        };
1590        let max_container_height = (box_constraints.max_height - bottom_height).max(0.0);
1591        let container_height = if expands {
1592            max_container_height
1593        } else {
1594            content_height
1595                .max(min_container_height)
1596                .min(max_container_height)
1597        };
1598
1599        // Ensure the text is vertically centered in cases where the content is
1600        // shorter than kMinInteractiveDimension.
1601        let interactive_adjustment = if min_container_height > content_height {
1602            (min_container_height - content_height) / 2.0
1603        } else {
1604            0.0
1605        };
1606
1607        // Try to consider the prefix/suffix as part of the text when aligning it.
1608        // If the prefix/suffix overflows however, allow it to extend outside of the
1609        // input and align the remaining part of the text and prefix/suffix.
1610        let overflow = (content_height - max_container_height).max(0.0);
1611        // Map textAlignVertical from -1:1 to 0:1 so that it can be used to scale
1612        // the baseline from its minimum to maximum values.
1613        let text_align_vertical = self.text_align_vertical(app);
1614        let text_align_vertical_factor = (text_align_vertical.y + 1.0) / 2.0;
1615        // Adjust to try to fit top overflow inside the input on an inverse scale of
1616        // textAlignVertical, so that top aligned text adjusts the most and bottom
1617        // aligned text doesn't adjust at all.
1618        let baseline_adjustment = fix_above_input - overflow * (1.0 - text_align_vertical_factor);
1619
1620        // The baselines that will be used to draw the actual input text content.
1621        let top_input_baseline = content_padding.top
1622            + top_height
1623            + input_internal_baseline
1624            + baseline_adjustment
1625            + interactive_adjustment
1626            + density_offset.dy() / 2.0;
1627        let max_content_height = container_height
1628            - (content_padding.top + content_padding.bottom)
1629            - top_height
1630            - density_offset.dy();
1631        let alignable_height = fix_above_input + input_height + fix_below_input;
1632        let max_vertical_offset = max_content_height - alignable_height;
1633
1634        let baseline = if self.is_outline_aligned(app) {
1635            // The three main alignments for the baseline when an outline is present are
1636            //
1637            //  * top (-1.0): topmost point considering padding.
1638            //  * center (0.0): the absolute center of the input ignoring padding but
1639            //      accommodating the border and floating label.
1640            //  * bottom (1.0): bottommost point considering padding.
1641            //
1642            // That means that if the padding is uneven, center is not the exact
1643            // midpoint of top and bottom. To account for this, the above center and
1644            // below center alignments are interpolated independently.
1645            let outline_center_baseline = input_internal_baseline
1646                + baseline_adjustment / 2.0
1647                + (container_height - input_height) / 2.0;
1648            let outline_top_baseline = top_input_baseline;
1649            let outline_bottom_baseline = top_input_baseline + max_vertical_offset;
1650            RenderDecoration::interpolate_three(
1651                outline_top_baseline,
1652                outline_center_baseline,
1653                outline_bottom_baseline,
1654                text_align_vertical,
1655            )
1656        } else {
1657            let text_align_vertical_offset = max_vertical_offset * text_align_vertical_factor;
1658            top_input_baseline + text_align_vertical_offset
1659        };
1660
1661        RenderDecorationLayout {
1662            input_constraints,
1663            container_height,
1664            baseline,
1665            supporting_text_size,
1666            size: Size::new(
1667                constraints.max_width,
1668                container_height
1669                    + supporting_text_size.map_or(0.0, |size| size.supporting_text_height),
1670            ),
1671        }
1672    }
1673
1674    // Interpolate between three stops using textAlignVertical. This is used to
1675    // calculate the outline baseline, which ignores padding when the alignment is
1676    // middle. When the alignment is less than zero, it interpolates between the
1677    // centered text box's top and the top of the content padding. When the
1678    // alignment is greater than zero, it interpolates between the centered box's
1679    // top and the position that would align the bottom of the box with the bottom
1680    // padding.
1681    fn interpolate_three(
1682        begin: f64,
1683        middle: f64,
1684        end: f64,
1685        text_align_vertical: TextAlignVertical,
1686    ) -> f64 {
1687        // It's possible for begin, middle, and end to not be in order because of
1688        // excessive padding. Those cases are handled by using middle.
1689        let basis = if text_align_vertical.y <= 0.0 {
1690            (middle - begin).max(0.0)
1691        } else {
1692            (end - middle).max(0.0)
1693        };
1694        middle + basis * text_align_vertical.y
1695    }
1696
1697    fn line_height(app: &mut App, width: f64, boxes: &[Option<AnyRenderBox>]) -> f64 {
1698        let mut height: f64 = 0.0;
1699        for r#box in boxes {
1700            let Some(r#box) = *r#box else {
1701                continue;
1702            };
1703            height = RenderDecoration::min_height(app, Some(r#box), width).max(height);
1704        }
1705        height
1706        // TODO(hansmuller): this should compute the overall line height for the
1707        // boxes when they've been baseline-aligned.
1708        // See https://github.com/flutter/flutter/issues/13715
1709    }
1710
1711    fn label_offset(app: &App, label: AnyRenderBox) -> Offset {
1712        RenderDecoration::box_parent_data(app, label).offset
1713    }
1714
1715    fn paint_label(
1716        self: RenderHandle<Self>,
1717        app: &mut App,
1718        context: &mut PaintingContext,
1719        offset: Offset,
1720    ) {
1721        let label = self
1722            .label(app)
1723            .expect("the label is painted only when there is one");
1724        context.paint_child(app, label.as_object(), offset);
1725    }
1726}
1727
1728impl SlottedContainerRenderObjectMixin<DecorationSlot> for RenderDecoration {
1729    type ChildType = AnyRenderBox;
1730
1731    fn slotted_container_data(
1732        self: RenderHandle<Self>,
1733        app: &App,
1734    ) -> &SlottedContainerRenderObjectData<DecorationSlot, AnyRenderBox> {
1735        &self.get(app).slotted
1736    }
1737
1738    fn slotted_container_data_mut(
1739        self: RenderHandle<Self>,
1740        app: &mut App,
1741    ) -> &mut SlottedContainerRenderObjectData<DecorationSlot, AnyRenderBox> {
1742        &mut self.get_mut(app).slotted
1743    }
1744
1745    // The returned list is ordered for hit testing.
1746    fn children(self: RenderHandle<Self>, app: &App) -> Vec<AnyRenderBox> {
1747        let helper_error = self.child_for_slot(app, &DecorationSlot::HelperError);
1748        [
1749            self.icon(app),
1750            self.input(app),
1751            self.prefix_icon(app),
1752            self.suffix_icon(app),
1753            self.prefix(app),
1754            self.suffix(app),
1755            self.label(app),
1756            self.hint(app),
1757            helper_error,
1758            self.counter(app),
1759            self.container(app),
1760        ]
1761        .into_iter()
1762        .flatten()
1763        .collect()
1764    }
1765}
1766
1767impl RenderObject for RenderDecoration {
1768    waft_rendering::render_object_accessors!();
1769
1770    fn debug_describe_children(
1771        self: RenderHandle<Self>,
1772        app: &App,
1773    ) -> Vec<Rc<dyn DiagnosticsNode>> {
1774        SlottedContainerRenderObjectMixin::debug_describe_children(self, app)
1775    }
1776
1777    fn did_attach(self: RenderHandle<Self>, app: &mut App, owner: Handle<PipelineOwner>) {
1778        SlottedContainerRenderObjectMixin::did_attach(self, app, owner);
1779    }
1780
1781    fn did_detach(self: RenderHandle<Self>, app: &mut App) {
1782        SlottedContainerRenderObjectMixin::did_detach(self, app);
1783    }
1784
1785    fn redepth_children(self: RenderHandle<Self>, app: &mut App) {
1786        SlottedContainerRenderObjectMixin::redepth_children(self, app);
1787    }
1788
1789    fn visit_children(
1790        self: RenderHandle<Self>,
1791        app: &App,
1792        visitor: &mut dyn FnMut(AnyRenderObject),
1793    ) {
1794        SlottedContainerRenderObjectMixin::visit_children(self, app, visitor);
1795    }
1796
1797    fn sized_by_parent(self: RenderHandle<Self>, _app: &App) -> bool {
1798        false
1799    }
1800
1801    fn perform_layout(self: RenderHandle<Self>, app: &mut App) {
1802        let constraints = self.constraints(app);
1803        self.get_mut(app).label_transform = None;
1804        let layout = self.layout(
1805            app,
1806            constraints,
1807            ChildLayoutHelper::layout_child,
1808            RenderDecoration::get_baseline,
1809        );
1810        let size = constraints.constrain(layout.size);
1811        self.set_size(app, size);
1812        debug_assert!(size.width() == constraints.constrain_width(layout.size.width()));
1813        debug_assert!(size.height() == constraints.constrain_height(layout.size.height()));
1814
1815        let overall_width = layout.size.width();
1816        let text_direction = self.text_direction(app);
1817        let decoration = self.decoration(app).clone();
1818        let content_padding = self.content_padding(app);
1819        let supporting_text_padding = decoration.supporting_text_padding;
1820        let icon = self.icon(app);
1821
1822        let container = self.container(app);
1823        if let Some(container) = container {
1824            let container_constraints = BoxConstraints::tight_for(
1825                Some(overall_width - RenderDecoration::box_size(app, icon).width()),
1826                Some(layout.container_height),
1827            );
1828            container.layout(app, container_constraints, true);
1829            let x = match text_direction {
1830                TextDirection::Rtl => 0.0,
1831                TextDirection::Ltr => RenderDecoration::box_size(app, icon).width(),
1832            };
1833            RenderDecoration::set_offset(app, container, Offset::new(x, 0.0));
1834        }
1835
1836        let height = layout.container_height;
1837        let center_layout = |app: &mut App, r#box: AnyRenderBox, x: f64| -> f64 {
1838            let box_size = r#box.size(app);
1839            RenderDecoration::set_offset(
1840                app,
1841                r#box,
1842                Offset::new(x, (height - box_size.height()) / 2.0),
1843            );
1844            box_size.width()
1845        };
1846
1847        if let Some(icon) = icon {
1848            let x = match text_direction {
1849                TextDirection::Rtl => overall_width - icon.size(app).width(),
1850                TextDirection::Ltr => 0.0,
1851            };
1852            center_layout(app, icon, x);
1853        }
1854
1855        let supporting_text_baseline =
1856            layout.supporting_text_size.map_or(0.0, |size| size.ascent) + layout.container_height;
1857        let counter = self.counter(app);
1858        let helper_error = self.helper_error(app);
1859        let helper_error_baseline = helper_error
1860            .get_distance_to_baseline(app, TextBaseline::Alphabetic, false)
1861            .expect("a baseline that falls back to the height");
1862        let counter_baseline = counter.map_or(0.0, |counter| {
1863            counter
1864                .get_distance_to_baseline(app, TextBaseline::Alphabetic, false)
1865                .expect("a baseline that falls back to the height")
1866        });
1867
1868        let icon_width = RenderDecoration::box_size(app, icon).width();
1869        let mut start;
1870        let mut end;
1871        let start_supporting;
1872        let end_supporting;
1873        match text_direction {
1874            TextDirection::Ltr => {
1875                start = content_padding.start + icon_width;
1876                end = overall_width - content_padding.end;
1877                start_supporting = supporting_text_padding
1878                    .map_or(content_padding.start, |padding| padding.start)
1879                    + icon_width;
1880                end_supporting = overall_width
1881                    - supporting_text_padding.map_or(content_padding.end, |padding| padding.end);
1882                RenderDecoration::set_offset(
1883                    app,
1884                    helper_error,
1885                    Offset::new(
1886                        start_supporting + decoration.input_gap,
1887                        supporting_text_baseline - helper_error_baseline,
1888                    ),
1889                );
1890                if let Some(counter) = counter {
1891                    let counter_width = counter.size(app).width();
1892                    RenderDecoration::set_offset(
1893                        app,
1894                        counter,
1895                        Offset::new(
1896                            end_supporting - counter_width - decoration.input_gap,
1897                            supporting_text_baseline - counter_baseline,
1898                        ),
1899                    );
1900                }
1901            }
1902            TextDirection::Rtl => {
1903                start = overall_width - content_padding.start - icon_width;
1904                end = content_padding.end;
1905                start_supporting = overall_width
1906                    - supporting_text_padding
1907                        .map_or(content_padding.start, |padding| padding.start)
1908                    - icon_width;
1909                end_supporting =
1910                    supporting_text_padding.map_or(content_padding.end, |padding| padding.end);
1911                let helper_error_width = helper_error.size(app).width();
1912                RenderDecoration::set_offset(
1913                    app,
1914                    helper_error,
1915                    Offset::new(
1916                        start_supporting - helper_error_width - decoration.input_gap,
1917                        supporting_text_baseline - helper_error_baseline,
1918                    ),
1919                );
1920                if let Some(counter) = counter {
1921                    RenderDecoration::set_offset(
1922                        app,
1923                        counter,
1924                        Offset::new(
1925                            end_supporting + decoration.input_gap,
1926                            supporting_text_baseline - counter_baseline,
1927                        ),
1928                    );
1929                }
1930            }
1931        }
1932
1933        let baseline = layout.baseline;
1934        let baseline_layout = |app: &mut App, r#box: AnyRenderBox, x: f64| -> f64 {
1935            let distance = r#box
1936                .get_distance_to_baseline(app, TextBaseline::Alphabetic, false)
1937                .expect("a baseline that falls back to the height");
1938            RenderDecoration::set_offset(app, r#box, Offset::new(x, baseline - distance));
1939            r#box.size(app).width()
1940        };
1941
1942        let prefix_icon = self.prefix_icon(app);
1943        let suffix_icon = self.suffix_icon(app);
1944        let label = self.label(app);
1945        let prefix = self.prefix(app);
1946        let suffix = self.suffix(app);
1947        let input = self.input(app);
1948        let hint = self.hint(app);
1949        let prefix_to_input_gap = self.prefix_to_input_gap(app);
1950        let input_to_suffix_gap = self.input_to_suffix_gap(app);
1951        match text_direction {
1952            TextDirection::Rtl => {
1953                if let Some(prefix_icon) = prefix_icon {
1954                    start += content_padding.start;
1955                    let x = start - prefix_icon.size(app).width();
1956                    start -= center_layout(app, prefix_icon, x);
1957                    start -= prefix_to_input_gap;
1958                } else {
1959                    start -= decoration.input_gap;
1960                }
1961                if let Some(label) = label {
1962                    let x = start - label.size(app).width();
1963                    if decoration.align_label_with_hint {
1964                        baseline_layout(app, label, x);
1965                    } else {
1966                        center_layout(app, label, x);
1967                    }
1968                }
1969                if let Some(prefix) = prefix {
1970                    let x = start - prefix.size(app).width();
1971                    start -= baseline_layout(app, prefix, x);
1972                }
1973                if let Some(input) = input {
1974                    let x = start - input.size(app).width();
1975                    baseline_layout(app, input, x);
1976                }
1977                if let Some(hint) = hint {
1978                    let x = start - hint.size(app).width();
1979                    baseline_layout(app, hint, x);
1980                }
1981                if let Some(suffix_icon) = suffix_icon {
1982                    end -= content_padding.end;
1983                    end += center_layout(app, suffix_icon, end);
1984                    end += input_to_suffix_gap;
1985                } else {
1986                    end += decoration.input_gap;
1987                }
1988                if let Some(suffix) = suffix {
1989                    baseline_layout(app, suffix, end);
1990                }
1991            }
1992            TextDirection::Ltr => {
1993                if let Some(prefix_icon) = prefix_icon {
1994                    start -= content_padding.start;
1995                    start += center_layout(app, prefix_icon, start);
1996                    start += prefix_to_input_gap;
1997                } else {
1998                    start += decoration.input_gap;
1999                }
2000                if let Some(label) = label {
2001                    if decoration.align_label_with_hint {
2002                        baseline_layout(app, label, start);
2003                    } else {
2004                        center_layout(app, label, start);
2005                    }
2006                }
2007                if let Some(prefix) = prefix {
2008                    start += baseline_layout(app, prefix, start);
2009                }
2010                if let Some(input) = input {
2011                    baseline_layout(app, input, start);
2012                }
2013                if let Some(hint) = hint {
2014                    baseline_layout(app, hint, start);
2015                }
2016                if let Some(suffix_icon) = suffix_icon {
2017                    end += content_padding.end;
2018                    let x = end - suffix_icon.size(app).width();
2019                    end -= center_layout(app, suffix_icon, x);
2020                    end -= input_to_suffix_gap;
2021                } else {
2022                    end -= decoration.input_gap;
2023                }
2024                if let Some(suffix) = suffix {
2025                    let x = end - suffix.size(app).width();
2026                    baseline_layout(app, suffix, x);
2027                }
2028            }
2029        }
2030
2031        let border_gap = decoration.border_gap;
2032        if let Some(label) = label {
2033            let label_x = RenderDecoration::label_offset(app, label).dx();
2034            // +1 shifts the range of x from (-1.0, 1.0) to (0.0, 2.0).
2035            let float_align = decoration.floating_label_alignment.x + 1.0;
2036            let label_width = RenderDecoration::box_size(app, Some(label)).width();
2037            let float_width = label_width * K_FINAL_LABEL_SCALE;
2038            let container_width = RenderDecoration::box_size(app, container).width();
2039            let prefix_icon_width = RenderDecoration::box_size(app, prefix_icon).width();
2040            let material3 = self.material3(app);
2041            // When floating label is centered, its x is relative to
2042            // _BorderContainer's x and is independent of label's x.
2043            match text_direction {
2044                TextDirection::Rtl => {
2045                    let mut offset_to_prefix_icon = 0.0;
2046                    if prefix_icon.is_some() && !decoration.align_label_with_hint {
2047                        offset_to_prefix_icon = if material3 {
2048                            prefix_icon_width - content_padding.end
2049                        } else {
2050                            0.0
2051                        };
2052                    }
2053                    border_gap.set_start(
2054                        app,
2055                        lerp_double(
2056                            Some(label_x + label_width + offset_to_prefix_icon),
2057                            Some(container_width / 2.0 + float_width / 2.0),
2058                            float_align,
2059                        ),
2060                    );
2061                }
2062                TextDirection::Ltr => {
2063                    // The value of _InputBorderGap.start is relative to the origin of the
2064                    // _BorderContainer which is inset by the icon's width. Although, when
2065                    // floating label is centered, it's already relative to _BorderContainer.
2066                    let mut offset_to_prefix_icon = 0.0;
2067                    if prefix_icon.is_some() && !decoration.align_label_with_hint {
2068                        offset_to_prefix_icon = if material3 {
2069                            -prefix_icon_width + content_padding.start
2070                        } else {
2071                            0.0
2072                        };
2073                    }
2074                    border_gap.set_start(
2075                        app,
2076                        lerp_double(
2077                            Some(label_x - icon_width + offset_to_prefix_icon),
2078                            Some(container_width / 2.0 - float_width / 2.0),
2079                            float_align,
2080                        ),
2081                    );
2082                }
2083            }
2084            border_gap.set_extent(app, label.size(app).width() * K_FINAL_LABEL_SCALE);
2085        } else {
2086            border_gap.set_start(app, None);
2087            border_gap.set_extent(app, 0.0);
2088        }
2089    }
2090
2091    fn paint(
2092        self: RenderHandle<Self>,
2093        app: &mut App,
2094        context: &mut PaintingContext,
2095        offset: Offset,
2096    ) {
2097        let do_paint =
2098            |app: &mut App, context: &mut PaintingContext, child: Option<AnyRenderBox>| {
2099                if let Some(child) = child {
2100                    let child_offset = RenderDecoration::box_parent_data(app, child).offset;
2101                    context.paint_child(app, child.as_object(), child_offset + offset);
2102                }
2103            };
2104
2105        let container = self.container(app);
2106        do_paint(app, context, container);
2107
2108        if let Some(label) = self.label(app) {
2109            let decoration = self.decoration(app).clone();
2110            let label_offset = RenderDecoration::label_offset(app, label);
2111            let label_height = RenderDecoration::box_size(app, Some(label)).height();
2112            let label_width = RenderDecoration::box_size(app, Some(label)).width();
2113            // +1 shifts the range of x from (-1.0, 1.0) to (0.0, 2.0).
2114            let float_align = decoration.floating_label_alignment.x + 1.0;
2115            let float_width = label_width * K_FINAL_LABEL_SCALE;
2116            let border_side = decoration.border.border_side();
2117            let t = decoration.floating_label_progress;
2118            // The center of the outline border label ends up a little below the
2119            // center of the top border line.
2120            let is_outline_border = decoration.border.is_outline();
2121            // Temporary opt-in fix for https://github.com/flutter/flutter/issues/54028
2122            // Center the scaled label relative to the border.
2123            let outlined_floating_y =
2124                (-label_height * K_FINAL_LABEL_SCALE) / 2.0 - border_side.stroke_offset() / 2.0;
2125            let floating_y = if is_outline_border {
2126                outlined_floating_y
2127            } else {
2128                decoration.content_padding.top + self.density_offset(app).dy() / 2.0
2129            };
2130            let scale =
2131                lerp_double(Some(1.0), Some(K_FINAL_LABEL_SCALE), t).expect("both ends are given");
2132            let container = container.expect("an input decorator always has a container");
2133            let centered_float_x = RenderDecoration::box_parent_data(app, container)
2134                .offset
2135                .dx()
2136                + RenderDecoration::box_size(app, Some(container)).width() / 2.0
2137                - float_width / 2.0;
2138            let prefix_icon = self.prefix_icon(app);
2139            let prefix_icon_width = RenderDecoration::box_size(app, prefix_icon).width();
2140            let material3 = self.material3(app);
2141            let start_x;
2142            let mut float_start_x;
2143            match self.text_direction(app) {
2144                // origin is on the right
2145                TextDirection::Rtl => {
2146                    start_x = label_offset.dx() + label_width * (1.0 - scale);
2147                    float_start_x = start_x;
2148                    if prefix_icon.is_some()
2149                        && !decoration.align_label_with_hint
2150                        && is_outline_border
2151                    {
2152                        float_start_x += if material3 {
2153                            prefix_icon_width - decoration.content_padding.end
2154                        } else {
2155                            0.0
2156                        };
2157                    }
2158                }
2159                // origin on the left
2160                TextDirection::Ltr => {
2161                    start_x = label_offset.dx();
2162                    float_start_x = start_x;
2163                    if prefix_icon.is_some()
2164                        && !decoration.align_label_with_hint
2165                        && is_outline_border
2166                    {
2167                        float_start_x += if material3 {
2168                            -prefix_icon_width + decoration.content_padding.start
2169                        } else {
2170                            0.0
2171                        };
2172                    }
2173                }
2174            }
2175            let float_end_x = lerp_double(Some(float_start_x), Some(centered_float_x), float_align)
2176                .expect("both ends are given");
2177            let dx = lerp_double(Some(start_x), Some(float_end_x), t).expect("both ends are given");
2178            let dy = lerp_double(Some(0.0), Some(floating_y - label_offset.dy()), t)
2179                .expect("both ends are given");
2180            // Dart's `Matrix4.identity()..translateByDouble(dx, labelOffset.dy + dy, 0, 1)
2181            // ..scaleByDouble(scale, scale, scale, 1)`, column-major.
2182            let (dx, dy, scale) = (dx as f32, (label_offset.dy() + dy) as f32, scale as f32);
2183            let label_transform = Matrix4::from_flutter_array(&[
2184                scale, 0.0, 0.0, 0.0, //
2185                0.0, scale, 0.0, 0.0, //
2186                0.0, 0.0, scale, 0.0, //
2187                dx, dy, 0.0, 1.0,
2188            ]);
2189            self.get_mut(app).label_transform = Some(label_transform);
2190            let old_layer = self.as_object().layer_as::<TransformLayer>(app);
2191            let needs_compositing = self.as_object().needs_compositing(app);
2192            let layer = context.push_transform(
2193                app,
2194                needs_compositing,
2195                offset,
2196                label_transform,
2197                |app, context, offset| self.paint_label(app, context, offset),
2198                old_layer,
2199            );
2200            self.as_object()
2201                .set_layer(app, layer.map(|layer| layer.as_container_layer()));
2202        } else {
2203            self.as_object().set_layer(app, None);
2204        }
2205
2206        do_paint(app, context, self.icon(app));
2207        do_paint(app, context, self.prefix(app));
2208        do_paint(app, context, self.suffix(app));
2209        do_paint(app, context, self.prefix_icon(app));
2210        do_paint(app, context, self.suffix_icon(app));
2211        if self.decoration(app).is_empty {
2212            do_paint(app, context, self.hint(app));
2213        }
2214        do_paint(app, context, self.input(app));
2215        do_paint(app, context, Some(self.helper_error(app)));
2216        do_paint(app, context, self.counter(app));
2217    }
2218}
2219
2220impl RenderBox for RenderDecoration {
2221    waft_rendering::render_box_accessors!();
2222
2223    fn compute_min_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
2224        let decoration = self.decoration(app).clone();
2225        let input = self.input(app);
2226        let input_width = if decoration.is_empty || decoration.maintain_hint_size {
2227            let input_width = RenderDecoration::min_width(app, input, height);
2228            let hint = self.hint(app);
2229            input_width.max(RenderDecoration::min_width(app, hint, height))
2230        } else {
2231            RenderDecoration::min_width(app, input, height)
2232        };
2233        let content_width = if decoration.maintain_label_size {
2234            let label = self.label(app);
2235            input_width.max(RenderDecoration::min_width(app, label, height))
2236        } else {
2237            input_width
2238        };
2239        let prefix_icon = self.prefix_icon(app);
2240        let suffix_icon = self.suffix_icon(app);
2241        let content_padding = self.content_padding(app);
2242        let leading_gap = if prefix_icon.is_some() {
2243            self.prefix_to_input_gap(app)
2244        } else {
2245            content_padding.start + decoration.input_gap
2246        };
2247        let trailing_gap = if suffix_icon.is_some() {
2248            self.input_to_suffix_gap(app)
2249        } else {
2250            content_padding.end + decoration.input_gap
2251        };
2252        let icon = self.icon(app);
2253        let prefix = self.prefix(app);
2254        let suffix = self.suffix(app);
2255        RenderDecoration::min_width(app, icon, height)
2256            + leading_gap
2257            + RenderDecoration::min_width(app, prefix_icon, height)
2258            + RenderDecoration::min_width(app, prefix, height)
2259            + content_width
2260            + RenderDecoration::min_width(app, suffix, height)
2261            + RenderDecoration::min_width(app, suffix_icon, height)
2262            + trailing_gap
2263    }
2264
2265    fn compute_max_intrinsic_width(self: RenderHandle<Self>, app: &mut App, height: f64) -> f64 {
2266        let decoration = self.decoration(app).clone();
2267        let input = self.input(app);
2268        let input_width = if decoration.is_empty || decoration.maintain_hint_size {
2269            let input_width = RenderDecoration::max_width(app, input, height);
2270            let hint = self.hint(app);
2271            input_width.max(RenderDecoration::max_width(app, hint, height))
2272        } else {
2273            RenderDecoration::max_width(app, input, height)
2274        };
2275        let content_width = if decoration.maintain_label_size {
2276            let label = self.label(app);
2277            input_width.max(RenderDecoration::max_width(app, label, height))
2278        } else {
2279            input_width
2280        };
2281        let prefix_icon = self.prefix_icon(app);
2282        let suffix_icon = self.suffix_icon(app);
2283        let content_padding = self.content_padding(app);
2284        let leading_gap = if prefix_icon.is_some() {
2285            self.prefix_to_input_gap(app)
2286        } else {
2287            content_padding.start + decoration.input_gap
2288        };
2289        let trailing_gap = if suffix_icon.is_some() {
2290            self.input_to_suffix_gap(app)
2291        } else {
2292            content_padding.end + decoration.input_gap
2293        };
2294        let icon = self.icon(app);
2295        let prefix = self.prefix(app);
2296        let suffix = self.suffix(app);
2297        RenderDecoration::max_width(app, icon, height)
2298            + leading_gap
2299            + RenderDecoration::max_width(app, prefix_icon, height)
2300            + RenderDecoration::max_width(app, prefix, height)
2301            + content_width
2302            + RenderDecoration::max_width(app, suffix, height)
2303            + RenderDecoration::max_width(app, suffix_icon, height)
2304            + trailing_gap
2305    }
2306
2307    fn compute_min_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
2308        let decoration = self.decoration(app).clone();
2309        let content_padding = self.content_padding(app);
2310        let supporting_text_padding = decoration.supporting_text_padding;
2311        let icon = self.icon(app);
2312        let icon_height = RenderDecoration::min_height(app, icon, width);
2313        let icon_width = RenderDecoration::min_width(app, icon, icon_height);
2314
2315        let width = (width - icon_width).max(0.0);
2316        let supporting_text_width = (width
2317            - supporting_text_padding
2318                .map_or(content_padding.start + content_padding.end, |padding| {
2319                    padding.start + padding.end
2320                })
2321            - decoration.input_gap * 2.0)
2322            .max(0.0);
2323
2324        let prefix_icon = self.prefix_icon(app);
2325        let prefix_icon_height = RenderDecoration::min_height(app, prefix_icon, width);
2326        let prefix_icon_width = RenderDecoration::min_width(app, prefix_icon, prefix_icon_height);
2327
2328        let suffix_icon = self.suffix_icon(app);
2329        let suffix_icon_height = RenderDecoration::min_height(app, suffix_icon, width);
2330        let suffix_icon_width = RenderDecoration::min_width(app, suffix_icon, suffix_icon_height);
2331
2332        let width =
2333            (width - (content_padding.start + content_padding.end) - decoration.input_gap * 2.0)
2334                .max(0.0);
2335
2336        // TODO(LongCatIsLooong): use _computeSupportingTextSizes for supportingText intrinsic sizes.
2337        // See https://github.com/flutter/flutter/issues/13715.
2338        let counter = self.counter(app);
2339        let counter_height = RenderDecoration::min_height(app, counter, supporting_text_width);
2340        let counter_width = RenderDecoration::min_width(app, counter, counter_height);
2341
2342        // Only add padding when counter is present (maxLength is used).
2343        let counter_padding = if counter.is_some() {
2344            K_SUPPORTING_TEXT_COUNTER_PADDING
2345        } else {
2346            0.0
2347        };
2348        let helper_error_available_width =
2349            (supporting_text_width - counter_width - counter_padding).max(0.0);
2350        let helper_error = self.helper_error(app);
2351        let helper_error_height =
2352            RenderDecoration::min_height(app, Some(helper_error), helper_error_available_width);
2353        let mut supporting_text_height = counter_height.max(helper_error_height);
2354        if supporting_text_height > 0.0 {
2355            let top_padding = supporting_text_padding
2356                .map_or_else(|| self.supporting_text_gap(app), |padding| padding.top);
2357            let bottom_padding = supporting_text_padding.map_or(0.0, |padding| padding.bottom);
2358            supporting_text_height += top_padding + bottom_padding;
2359        }
2360
2361        let prefix = self.prefix(app);
2362        let prefix_height = RenderDecoration::min_height(app, prefix, width);
2363        let prefix_width = RenderDecoration::min_width(app, prefix, prefix_height);
2364
2365        let suffix = self.suffix(app);
2366        let suffix_height = RenderDecoration::min_height(app, suffix, width);
2367        let suffix_width = RenderDecoration::min_width(app, suffix, suffix_height);
2368
2369        let available_input_width =
2370            (width - prefix_width - suffix_width - prefix_icon_width - suffix_icon_width).max(0.0);
2371        let input = self.input(app);
2372        let hint = if decoration.is_empty {
2373            self.hint(app)
2374        } else {
2375            None
2376        };
2377        let input_height =
2378            RenderDecoration::line_height(app, available_input_width, &[input, hint]);
2379        let input_max_height = [input_height, prefix_height, suffix_height]
2380            .into_iter()
2381            .fold(f64::NEG_INFINITY, f64::max);
2382
2383        let label = self.label(app);
2384        let content_height = content_padding.top
2385            + if label.is_none() {
2386                0.0
2387            } else {
2388                decoration.floating_label_height
2389            }
2390            + input_max_height
2391            + content_padding.bottom
2392            + self.density_offset(app).dy();
2393        let container_height = [
2394            icon_height,
2395            content_height,
2396            prefix_icon_height,
2397            suffix_icon_height,
2398        ]
2399        .into_iter()
2400        .fold(f64::NEG_INFINITY, f64::max);
2401        // Keep in sync with the minimum container height computed in _layout.
2402        let min_container_height = if decoration.is_dense.expect("applied from the theme")
2403            || decoration.is_collapsed
2404            || self.expands(app)
2405        {
2406            input_height
2407        } else {
2408            K_MIN_INTERACTIVE_DIMENSION
2409        };
2410
2411        container_height.max(min_container_height) + supporting_text_height
2412    }
2413
2414    fn compute_max_intrinsic_height(self: RenderHandle<Self>, app: &mut App, width: f64) -> f64 {
2415        self.as_box().get_min_intrinsic_height(app, width)
2416    }
2417
2418    fn compute_distance_to_actual_baseline(
2419        self: RenderHandle<Self>,
2420        app: &mut App,
2421        baseline: TextBaseline,
2422    ) -> Option<f64> {
2423        let Some(input) = self.input(app) else {
2424            return Some(0.0);
2425        };
2426        let offset_dy = RenderDecoration::box_parent_data(app, input).offset.dy();
2427        let distance = input
2428            .get_distance_to_actual_baseline(app, baseline)
2429            .unwrap_or_else(|| input.size(app).height());
2430        Some(offset_dy + distance)
2431    }
2432
2433    fn compute_dry_baseline(
2434        self: RenderHandle<Self>,
2435        app: &mut App,
2436        constraints: BoxConstraints,
2437        baseline: TextBaseline,
2438    ) -> Option<f64> {
2439        let Some(input) = self.input(app) else {
2440            return Some(0.0);
2441        };
2442        let layout = self.layout(
2443            app,
2444            constraints,
2445            ChildLayoutHelper::dry_layout_child,
2446            RenderDecoration::get_dry_baseline,
2447        );
2448        let baseline_offset = match baseline {
2449            TextBaseline::Alphabetic => 0.0,
2450            TextBaseline::Ideographic => {
2451                let ideographic = input
2452                    .get_dry_baseline(app, layout.input_constraints, TextBaseline::Ideographic)
2453                    .unwrap_or_else(|| {
2454                        input.get_dry_layout(app, layout.input_constraints).height()
2455                    });
2456                let alphabetic = input
2457                    .get_dry_baseline(app, layout.input_constraints, TextBaseline::Alphabetic)
2458                    .unwrap_or_else(|| {
2459                        input.get_dry_layout(app, layout.input_constraints).height()
2460                    });
2461                ideographic - alphabetic
2462            }
2463        };
2464        Some(baseline_offset + layout.baseline)
2465    }
2466
2467    fn compute_dry_layout(
2468        self: RenderHandle<Self>,
2469        app: &mut App,
2470        constraints: BoxConstraints,
2471    ) -> Size {
2472        let layout = self.layout(
2473            app,
2474            constraints,
2475            ChildLayoutHelper::dry_layout_child,
2476            RenderDecoration::get_dry_baseline,
2477        );
2478        constraints.constrain(layout.size)
2479    }
2480
2481    fn apply_paint_transform(
2482        self: RenderHandle<Self>,
2483        app: &App,
2484        child: AnyRenderObject,
2485        transform: &mut Matrix4,
2486    ) {
2487        if let Some(label) = self.label(app)
2488            && child == label.as_object()
2489            && let Some(label_transform) = self.get(app).label_transform
2490        {
2491            let label_offset = RenderDecoration::label_offset(app, label);
2492            *transform = transform.then(&label_transform).then(&Matrix4::translation(
2493                -label_offset.dx() as f32,
2494                -label_offset.dy() as f32,
2495            ));
2496        }
2497        // Dart's `super.applyPaintTransform`: `RenderBox`'s, which translates by the child's
2498        // offset.
2499        let offset = child.parent_data_of::<BoxParentData>(app).offset;
2500        *transform = transform.then(&Matrix4::translation(
2501            offset.dx() as f32,
2502            offset.dy() as f32,
2503        ));
2504    }
2505
2506    fn hit_test_self(self: RenderHandle<Self>, _app: &App, _position: Offset) -> bool {
2507        true
2508    }
2509
2510    fn hit_test_children(
2511        self: RenderHandle<Self>,
2512        app: &mut App,
2513        result: &mut BoxHitTestResult<'_>,
2514        position: Offset,
2515    ) -> bool {
2516        let label = self.label(app);
2517        for child in SlottedContainerRenderObjectMixin::children(self, app) {
2518            // The label must be handled specially since we've transformed it.
2519            if Some(child) == label && self.get(app).label_transform.is_some() {
2520                let mut transform = Matrix4::IDENTITY;
2521                RenderBox::apply_paint_transform(self, app, child.as_object(), &mut transform);
2522                if result.add_with_paint_transform(
2523                    Some(transform),
2524                    position,
2525                    |result, transformed| child.hit_test(app, result, transformed),
2526                ) {
2527                    return true;
2528                }
2529                continue;
2530            }
2531            let offset = RenderDecoration::box_parent_data(app, child).offset;
2532            let is_hit =
2533                result.add_with_paint_offset(Some(offset), position, |result, transformed| {
2534                    debug_assert!(transformed == position - offset);
2535                    child.hit_test(app, result, transformed)
2536                });
2537            if is_hit {
2538                return true;
2539            }
2540        }
2541        false
2542    }
2543}
2544
2545impl Debug for RenderDecoration {
2546    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2547        f.debug_struct("_RenderDecoration")
2548            .field("decoration", &self.decoration)
2549            .finish_non_exhaustive()
2550    }
2551}
2552
2553/// Dart's `_Decorator`.
2554#[derive(Debug)]
2555struct Decorator {
2556    decoration: Decoration,
2557    text_direction: TextDirection,
2558    text_baseline: TextBaseline,
2559    text_align_vertical: Option<TextAlignVertical>,
2560    is_focused: bool,
2561    expands: bool,
2562}
2563
2564impl SlottedMultiChildRenderObjectWidget for Decorator {
2565    type Slot = DecorationSlot;
2566
2567    fn slots(&self) -> Vec<DecorationSlot> {
2568        DecorationSlot::VALUES.to_vec()
2569    }
2570
2571    fn child_for_slot(&self, slot: &DecorationSlot) -> Option<WidgetRef> {
2572        let decoration = &self.decoration;
2573        match slot {
2574            DecorationSlot::Icon => decoration.icon.clone(),
2575            DecorationSlot::Input => decoration.input.clone(),
2576            DecorationSlot::Label => decoration.label.clone(),
2577            DecorationSlot::Hint => decoration.hint.clone(),
2578            DecorationSlot::Prefix => decoration.prefix.clone(),
2579            DecorationSlot::Suffix => decoration.suffix.clone(),
2580            DecorationSlot::PrefixIcon => decoration.prefix_icon.clone(),
2581            DecorationSlot::SuffixIcon => decoration.suffix_icon.clone(),
2582            DecorationSlot::HelperError => decoration.helper_error.clone(),
2583            DecorationSlot::Counter => decoration.counter.clone(),
2584            DecorationSlot::Container => decoration.container.clone(),
2585        }
2586    }
2587}
2588
2589impl RenderObjectWidget for Decorator {
2590    type RenderObject = RenderDecoration;
2591
2592    fn create_render_object(&self, app: &mut App, context: BuildContext) -> AnyRenderObject {
2593        let material3 = Theme::of(app, context).use_material3;
2594        RenderDecoration::new(
2595            app,
2596            self.decoration.clone(),
2597            self.text_direction,
2598            self.text_baseline,
2599            self.is_focused,
2600            self.expands,
2601            material3,
2602            self.text_align_vertical,
2603        )
2604        .as_object()
2605    }
2606
2607    fn update_render_object(
2608        &self,
2609        app: &mut App,
2610        _context: BuildContext,
2611        render_object: RenderHandle<RenderDecoration>,
2612    ) {
2613        render_object.set_decoration(app, self.decoration.clone());
2614        render_object.set_expands(app, self.expands);
2615        render_object.set_is_focused(app, self.is_focused);
2616        render_object.set_text_align_vertical(app, self.text_align_vertical);
2617        render_object.set_text_baseline(app, self.text_baseline);
2618        render_object.set_text_direction(app, self.text_direction);
2619    }
2620}
2621
2622/// Dart's `_AffixText`.
2623#[derive(Debug)]
2624struct AffixText {
2625    label_is_floating: bool,
2626    text: Option<String>,
2627    style: Option<TextStyle>,
2628    child: Option<WidgetRef>,
2629}
2630
2631impl StatelessWidget for AffixText {
2632    fn key(&self) -> Option<&KeyRef> {
2633        None
2634    }
2635
2636    fn build(&self, _app: &mut App, _context: BuildContext) -> WidgetRef {
2637        // `Semantics(sortKey:, tagForChildren:)` around the child waits with accessibility.
2638        let child = self.child.clone().or_else(|| {
2639            self.text.as_ref().map(|text| {
2640                let mut text = Text::new(text.clone());
2641                if let Some(style) = &self.style {
2642                    text = text.style(style.clone());
2643                }
2644                text.into_widget()
2645            })
2646        });
2647        let mut opacity = AnimatedOpacity::new(
2648            if self.label_is_floating { 1.0 } else { 0.0 },
2649            K_TRANSITION_DURATION,
2650        )
2651        .curve(k_transition_curve());
2652        if let Some(child) = child {
2653            opacity = opacity.child(child);
2654        }
2655        let mut merge = DefaultTextStyle::merge(
2656            IgnorePointer::new()
2657                .ignoring(!self.label_is_floating)
2658                .child(opacity),
2659        );
2660        if let Some(style) = &self.style {
2661            merge = merge.style(style.clone());
2662        }
2663        merge.into_widget()
2664    }
2665}
2666
2667/// Defines the appearance of a Material Design text field.
2668///
2669/// [`InputDecorator`] displays the visual elements of a Material Design text
2670/// field around its input [`child`](Self::child). The visual elements themselves are defined
2671/// by an [`InputDecoration`] object and their layout and appearance depend
2672/// on the `base_style`, `text_align`, `is_focused`, and `is_empty` parameters.
2673///
2674/// `TextField` uses this widget to decorate its `EditableText` child.
2675///
2676/// [`InputDecorator`] can be used to create widgets that look and behave like a
2677/// `TextField` but support other kinds of input.
2678///
2679/// Requires one of its ancestors to be a `Material` widget. The [`child`](Self::child) widget,
2680/// as well as the decorative widgets specified in [`decoration`](Self::decoration), must have
2681/// non-negative baselines.
2682///
2683/// See also:
2684///
2685///  * `TextField`, which uses an [`InputDecorator`] to display a border,
2686///    labels, and icons, around its `EditableText` child.
2687///  * `Decoration` and `DecoratedBox`, for drawing arbitrary decorations
2688///    around other widgets.
2689#[derive(Clone)]
2690pub struct InputDecorator {
2691    pub key: Option<KeyRef>,
2692
2693    /// The text and styles to use when decorating the child.
2694    ///
2695    /// Null [`InputDecoration`] properties are initialized with the corresponding
2696    /// values from the ambient [`InputDecorationThemeData`].
2697    pub decoration: InputDecoration,
2698
2699    /// The style on which to base the label, hint, counter, and error styles
2700    /// if the [`decoration`](Self::decoration) does not provide explicit styles.
2701    ///
2702    /// If null, [`base_style`](Self::base_style) defaults to the `title_medium` style from the
2703    /// current `Theme`, see `ThemeData::text_theme`.
2704    ///
2705    /// The `TextStyle::text_baseline` of the [`base_style`](Self::base_style) is used to
2706    /// determine the baseline used for text alignment.
2707    pub base_style: Option<TextStyle>,
2708
2709    /// How the text in the decoration should be aligned horizontally.
2710    pub text_align: Option<TextAlign>,
2711
2712    /// How the text should be aligned vertically.
2713    ///
2714    /// Determines the alignment of the baseline within the available space of
2715    /// the input (typically a TextField). For example, `TextAlignVertical::TOP` will
2716    /// place the baseline such that the text, and any attached decoration like
2717    /// prefix and suffix, is as close to the top of the input as possible without
2718    /// overflowing. The heights of the prefix and suffix are similarly included
2719    /// for other alignment values. If the height is greater than the height
2720    /// available, then the prefix and suffix will be allowed to overflow first
2721    /// before the text scrolls.
2722    pub text_align_vertical: Option<TextAlignVertical>,
2723
2724    /// Whether the input field has focus.
2725    ///
2726    /// Determines the position of the label text and the color and weight of the
2727    /// border.
2728    ///
2729    /// Defaults to false.
2730    ///
2731    /// See also:
2732    ///
2733    ///  * [`InputDecoration::hover_color`], which is also blended into the focus
2734    ///    color and fill color when the [`is_hovering`](Self::is_hovering) is true to produce
2735    ///    the final color.
2736    pub is_focused: bool,
2737
2738    /// Whether the input field is being hovered over by a mouse pointer.
2739    ///
2740    /// Determines the container fill color, which is a blend of
2741    /// [`InputDecoration::hover_color`] with [`InputDecoration::fill_color`] when
2742    /// true, and [`InputDecoration::fill_color`] when not.
2743    ///
2744    /// Defaults to false.
2745    pub is_hovering: bool,
2746
2747    /// If true, the height of the input field will be as large as possible.
2748    ///
2749    /// If wrapped in a widget that constrains its child's height, like Expanded
2750    /// or SizedBox, the input field will only be affected if [`expands`](Self::expands) is
2751    /// set to true.
2752    ///
2753    /// See `TextField::min_lines` and `TextField::max_lines` for related ways to
2754    /// affect the height of an input. When [`expands`](Self::expands) is true, both must be
2755    /// null in order to avoid ambiguity in determining the height.
2756    ///
2757    /// Defaults to false.
2758    pub expands: bool,
2759
2760    /// Whether the input field is empty.
2761    ///
2762    /// Determines the position of the label text and whether to display the hint
2763    /// text.
2764    ///
2765    /// Defaults to false.
2766    pub is_empty: bool,
2767
2768    /// The widget below this widget in the tree.
2769    ///
2770    /// Typically an `EditableText`, `DropdownButton`, or `InkWell`.
2771    pub child: Option<WidgetRef>,
2772}
2773
2774impl InputDecorator {
2775    /// Creates a widget that displays a border, labels, and icons,
2776    /// for a `TextField`.
2777    pub fn new(decoration: InputDecoration) -> InputDecorator {
2778        InputDecorator {
2779            key: None,
2780            decoration,
2781            base_style: None,
2782            text_align: None,
2783            text_align_vertical: None,
2784            is_focused: false,
2785            is_hovering: false,
2786            expands: false,
2787            is_empty: false,
2788            child: None,
2789        }
2790    }
2791
2792    /// Dart `InputDecorator(key:)`.
2793    pub fn key(mut self, key: KeyRef) -> InputDecorator {
2794        self.key = Some(key);
2795        self
2796    }
2797
2798    /// Dart `InputDecorator(baseStyle:)`.
2799    pub fn base_style(mut self, base_style: TextStyle) -> InputDecorator {
2800        self.base_style = Some(base_style);
2801        self
2802    }
2803
2804    /// Dart `InputDecorator(textAlign:)`.
2805    pub fn text_align(mut self, text_align: TextAlign) -> InputDecorator {
2806        self.text_align = Some(text_align);
2807        self
2808    }
2809
2810    /// Dart `InputDecorator(textAlignVertical:)`.
2811    pub fn text_align_vertical(mut self, text_align_vertical: TextAlignVertical) -> InputDecorator {
2812        self.text_align_vertical = Some(text_align_vertical);
2813        self
2814    }
2815
2816    /// Dart `InputDecorator(isFocused:)`.
2817    pub fn is_focused(mut self, is_focused: bool) -> InputDecorator {
2818        self.is_focused = is_focused;
2819        self
2820    }
2821
2822    /// Dart `InputDecorator(isHovering:)`.
2823    pub fn is_hovering(mut self, is_hovering: bool) -> InputDecorator {
2824        self.is_hovering = is_hovering;
2825        self
2826    }
2827
2828    /// Dart `InputDecorator(expands:)`.
2829    pub fn expands(mut self, expands: bool) -> InputDecorator {
2830        self.expands = expands;
2831        self
2832    }
2833
2834    /// Dart `InputDecorator(isEmpty:)`.
2835    pub fn is_empty(mut self, is_empty: bool) -> InputDecorator {
2836        self.is_empty = is_empty;
2837        self
2838    }
2839
2840    /// Dart `InputDecorator(child:)`.
2841    #[cfg_attr(debug_assertions, track_caller)]
2842    pub fn child<K>(mut self, child: impl IntoWidget<K>) -> InputDecorator {
2843        self.child = Some(child.into_widget());
2844        self
2845    }
2846
2847    /// Whether the label needs to get out of the way of the input, either by
2848    /// floating or disappearing.
2849    ///
2850    /// Will withdraw when not empty or when focused while enabled.
2851    fn label_should_withdraw(&self) -> bool {
2852        !self.is_empty || (self.is_focused && self.decoration.enabled)
2853    }
2854
2855    /// The RenderBox that defines this decorator's "container". That's the
2856    /// area which is filled if [`InputDecoration::filled`] is true. It's the area
2857    /// adjacent to [`InputDecoration::icon`] and above the widgets that contain
2858    /// [`InputDecoration::helper_text`], [`InputDecoration::error_text`], and
2859    /// [`InputDecoration::counter_text`].
2860    ///
2861    /// `TextField` renders ink splashes within the container.
2862    pub fn container_of(app: &App, context: BuildContext) -> Option<AnyRenderBox> {
2863        context
2864            .find_ancestor_render_object_of_type::<RenderDecoration>(app)
2865            .and_then(|result| result.container(app))
2866    }
2867}
2868
2869impl StatefulWidget for InputDecorator {
2870    type State = InputDecoratorState;
2871
2872    fn key(&self) -> Option<&KeyRef> {
2873        self.key.as_ref()
2874    }
2875
2876    fn debug_fill_properties(&self, _app: &App, properties: &mut DiagnosticPropertiesBuilder) {
2877        properties.add(DiagnosticsProperty::<InputDecoration>::new(
2878            "decoration",
2879            Some(self.decoration.clone()),
2880        ));
2881        properties.add(
2882            DiagnosticsProperty::<TextStyle>::new("baseStyle", self.base_style.clone())
2883                .default_value(None),
2884        );
2885        properties.add(DiagnosticsProperty::<bool>::new(
2886            "isFocused",
2887            self.is_focused,
2888        ));
2889        properties.add(
2890            DiagnosticsProperty::<bool>::new("expands", self.expands).default_value(Some(false)),
2891        );
2892        properties.add(DiagnosticsProperty::<bool>::new("isEmpty", self.is_empty));
2893    }
2894
2895    fn debug_check_constructor(&self) {
2896        self.decoration.debug_check_arguments();
2897    }
2898
2899    fn create_state(&self) -> InputDecoratorState {
2900        InputDecoratorState {
2901            state: StateData::new(),
2902            ticker_provider: TickerProviderStateMixinData::new(),
2903            floating_label_controller: None,
2904            floating_label_animation: None,
2905            shaking_label_controller: None,
2906            border_gap: None,
2907            effective_decoration: None,
2908            curved_animation: None,
2909        }
2910    }
2911}
2912
2913impl Debug for InputDecorator {
2914    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2915        let mut debug = f.debug_struct("InputDecorator");
2916        debug.field("decoration", &self.decoration);
2917        if let Some(base_style) = &self.base_style {
2918            debug.field("baseStyle", base_style);
2919        }
2920        debug.field("isFocused", &self.is_focused);
2921        if self.expands {
2922            debug.field("expands", &self.expands);
2923        }
2924        debug.field("isEmpty", &self.is_empty);
2925        debug.finish()
2926    }
2927}
2928
2929/// Dart's `_InputDecoratorState`. Its `late final` fields and the `_InputBorderGap` its
2930/// field initializer makes are created in `init_state`, because an arena object needs the
2931/// [`App`].
2932pub struct InputDecoratorState {
2933    state: StateData<InputDecorator>,
2934    ticker_provider: TickerProviderStateMixinData,
2935    floating_label_controller: Option<Ref<AnimationController>>,
2936    floating_label_animation: Option<Ref<CurvedAnimation>>,
2937    shaking_label_controller: Option<Ref<AnimationController>>,
2938    border_gap: Option<Ref<InputBorderGap>>,
2939    effective_decoration: Option<InputDecoration>,
2940    curved_animation: Option<Ref<CurvedAnimation>>,
2941}
2942
2943impl InputDecoratorState {
2944    fn floating_label_controller(self: Handle<Self>, app: &App) -> Ref<AnimationController> {
2945        app.get(self)
2946            .floating_label_controller
2947            .clone()
2948            .expect("created in init_state")
2949    }
2950
2951    fn floating_label_animation(self: Handle<Self>, app: &App) -> Ref<CurvedAnimation> {
2952        app.get(self)
2953            .floating_label_animation
2954            .clone()
2955            .expect("created in init_state")
2956    }
2957
2958    fn shaking_label_controller(self: Handle<Self>, app: &App) -> Ref<AnimationController> {
2959        app.get(self)
2960            .shaking_label_controller
2961            .clone()
2962            .expect("created in init_state")
2963    }
2964
2965    fn border_gap(self: Handle<Self>, app: &App) -> Ref<InputBorderGap> {
2966        app.get(self)
2967            .border_gap
2968            .clone()
2969            .expect("created in init_state")
2970    }
2971
2972    fn handle_change(self: Handle<Self>, app: &mut App) {
2973        self.set_state(app, |_state| {
2974            // The _floatingLabelController's value has changed.
2975        });
2976    }
2977
2978    /// Dart's `decoration` getter: the widget's decoration with the ambient theme's
2979    /// defaults applied, worked out once until the widget or the dependencies change.
2980    fn decoration(self: Handle<Self>, app: &mut App) -> &InputDecoration {
2981        if app.get(self).effective_decoration.is_none() {
2982            let context = self.context(app);
2983            let theme = InputDecorationTheme::of(app, context);
2984            let effective = self.widget(app).decoration.apply_defaults(theme);
2985            app.get_mut(self).effective_decoration = Some(effective);
2986        }
2987        app.get(self)
2988            .effective_decoration
2989            .as_ref()
2990            .expect("worked out above")
2991    }
2992
2993    fn text_align(self: Handle<Self>, app: &App) -> Option<TextAlign> {
2994        self.widget(app).text_align
2995    }
2996
2997    fn is_focused(self: Handle<Self>, app: &App) -> bool {
2998        self.widget(app).is_focused
2999    }
3000
3001    fn has_error(self: Handle<Self>, app: &mut App) -> bool {
3002        let decoration = self.decoration(app);
3003        decoration.error_text.is_some() || decoration.error.is_some()
3004    }
3005
3006    fn is_hovering(self: Handle<Self>, app: &mut App) -> bool {
3007        let enabled = self.decoration(app).enabled;
3008        self.widget(app).is_hovering && enabled
3009    }
3010
3011    fn is_empty(self: Handle<Self>, app: &App) -> bool {
3012        self.widget(app).is_empty
3013    }
3014
3015    fn floating_label_enabled(self: Handle<Self>, app: &mut App) -> bool {
3016        self.decoration(app).floating_label_behavior != Some(FloatingLabelBehavior::Never)
3017    }
3018
3019    fn label_should_withdraw(self: Handle<Self>, app: &mut App) -> bool {
3020        let always =
3021            self.decoration(app).floating_label_behavior == Some(FloatingLabelBehavior::Always);
3022        self.widget(app).label_should_withdraw() || always
3023    }
3024
3025    fn get_default_m2_border_color(
3026        self: Handle<Self>,
3027        app: &mut App,
3028        theme_data: &ThemeData,
3029    ) -> Color {
3030        let is_focused = self.is_focused(app);
3031        let has_error = self.has_error(app);
3032        let is_hovering = self.is_hovering(app);
3033        let decoration = self.decoration(app);
3034        if !decoration.enabled && !is_focused {
3035            return if decoration.filled.unwrap_or(false)
3036                && !decoration
3037                    .border
3038                    .as_ref()
3039                    .is_some_and(|border| border.is_outline())
3040            {
3041                Colors::TRANSPARENT
3042            } else {
3043                theme_data.disabled_color
3044            };
3045        }
3046        if has_error {
3047            return theme_data.color_scheme.error();
3048        }
3049        if is_focused {
3050            return theme_data.color_scheme.primary();
3051        }
3052        if decoration.filled.expect("applied from the theme") {
3053            return theme_data.hint_color;
3054        }
3055        // Dart's `withOpacity`, deprecated there too: its rounding to an 8-bit alpha is part of
3056        // the behaviour being ported.
3057        #[allow(deprecated)]
3058        let enabled_color = theme_data.color_scheme.on_surface().with_opacity(0.38);
3059        if is_hovering {
3060            let hover_color = decoration.hover_color.unwrap_or(theme_data.hover_color);
3061            #[allow(deprecated)]
3062            return Color::alpha_blend(hover_color.with_opacity(0.12), enabled_color);
3063        }
3064        enabled_color
3065    }
3066
3067    fn get_fill_color(
3068        self: Handle<Self>,
3069        app: &mut App,
3070        _theme_data: &ThemeData,
3071        defaults: &dyn InputDecorationThemeDataGetters,
3072    ) -> Color {
3073        let widget_state = self.widget_state(app);
3074        let decoration = self.decoration(app);
3075        if decoration.filled != Some(true) {
3076            // filled == null same as filled == false
3077            return Colors::TRANSPARENT;
3078        }
3079        if let Some(fill_color) = &decoration.fill_color {
3080            return *<dyn WidgetStateProperty<Color>>::resolve_as(fill_color, &widget_state);
3081        }
3082        *<dyn WidgetStateProperty<Color>>::resolve_as(
3083            defaults
3084                .fill_color(app)
3085                .as_ref()
3086                .expect("the defaults give one"),
3087            &widget_state,
3088        )
3089    }
3090
3091    fn get_hover_color(self: Handle<Self>, app: &mut App, theme_data: &ThemeData) -> Color {
3092        let decoration = self.decoration(app);
3093        if decoration.filled.is_none() || !decoration.filled.unwrap_or(false) || !decoration.enabled
3094        {
3095            return Colors::TRANSPARENT;
3096        }
3097        decoration.hover_color.unwrap_or(theme_data.hover_color)
3098    }
3099
3100    fn get_icon_color(
3101        self: Handle<Self>,
3102        app: &mut App,
3103        _theme_data: &ThemeData,
3104        defaults: &dyn InputDecorationThemeDataGetters,
3105    ) -> Color {
3106        let widget_state = self.widget_state(app);
3107        let decoration = self.decoration(app);
3108        <dyn WidgetStateProperty<Color>>::resolve_as(&decoration.icon_color, &widget_state)
3109            .map(|color| *color)
3110            .unwrap_or_else(|| {
3111                *<dyn WidgetStateProperty<Color>>::resolve_as(
3112                    defaults
3113                        .icon_color(app)
3114                        .as_ref()
3115                        .expect("the defaults give one"),
3116                    &widget_state,
3117                )
3118            })
3119    }
3120
3121    fn get_prefix_icon_color(
3122        self: Handle<Self>,
3123        app: &mut App,
3124        icon_button_theme: &IconButtonThemeData,
3125        defaults: &dyn InputDecorationThemeDataGetters,
3126    ) -> Color {
3127        let widget_state = self.widget_state(app);
3128        let decoration = self.decoration(app);
3129        <dyn WidgetStateProperty<Color>>::resolve_as(&decoration.prefix_icon_color, &widget_state)
3130            .map(|color| *color)
3131            .or_else(|| {
3132                icon_button_theme
3133                    .style
3134                    .as_ref()
3135                    .and_then(|style| style.foreground_color.as_ref())
3136                    .and_then(|foreground_color| foreground_color.resolve(&widget_state))
3137            })
3138            .unwrap_or_else(|| {
3139                *<dyn WidgetStateProperty<Color>>::resolve_as(
3140                    defaults
3141                        .prefix_icon_color(app)
3142                        .as_ref()
3143                        .expect("the defaults give one"),
3144                    &widget_state,
3145                )
3146            })
3147    }
3148
3149    fn get_suffix_icon_color(
3150        self: Handle<Self>,
3151        app: &mut App,
3152        icon_button_theme: &IconButtonThemeData,
3153        defaults: &dyn InputDecorationThemeDataGetters,
3154    ) -> Color {
3155        let widget_state = self.widget_state(app);
3156        let decoration = self.decoration(app);
3157        <dyn WidgetStateProperty<Color>>::resolve_as(&decoration.suffix_icon_color, &widget_state)
3158            .map(|color| *color)
3159            .or_else(|| {
3160                icon_button_theme
3161                    .style
3162                    .as_ref()
3163                    .and_then(|style| style.foreground_color.as_ref())
3164                    .and_then(|foreground_color| foreground_color.resolve(&widget_state))
3165            })
3166            .unwrap_or_else(|| {
3167                *<dyn WidgetStateProperty<Color>>::resolve_as(
3168                    defaults
3169                        .suffix_icon_color(app)
3170                        .as_ref()
3171                        .expect("the defaults give one"),
3172                    &widget_state,
3173                )
3174            })
3175    }
3176
3177    // True if the label will be shown and the hint will not.
3178    // If we're not focused, there's no value, labelText was provided, and
3179    // floatingLabelBehavior isn't set to always, then the label appears where the
3180    // hint would.
3181    fn has_inline_label(self: Handle<Self>, app: &mut App) -> bool {
3182        let label_should_withdraw = self.label_should_withdraw(app);
3183        let decoration = self.decoration(app);
3184        !label_should_withdraw && (decoration.label_text.is_some() || decoration.label.is_some())
3185    }
3186
3187    // If the label is a floating placeholder, it's always shown.
3188    fn should_show_label(self: Handle<Self>, app: &mut App) -> bool {
3189        self.has_inline_label(app) || self.floating_label_enabled(app)
3190    }
3191
3192    // The base style for the inline label when they're displayed "inline",
3193    // i.e. when they appear in place of the empty text field.
3194    fn get_inline_label_style(
3195        self: Handle<Self>,
3196        app: &mut App,
3197        theme_data: &ThemeData,
3198        defaults: &dyn InputDecorationThemeDataGetters,
3199    ) -> TextStyle {
3200        let widget_state = self.widget_state(app);
3201        let default_style = <dyn WidgetStateProperty<TextStyle>>::resolve_as(
3202            defaults
3203                .label_style(app)
3204                .as_ref()
3205                .expect("the defaults give one"),
3206            &widget_state,
3207        );
3208
3209        let style = <dyn WidgetStateProperty<TextStyle>>::resolve_as(
3210            &self.decoration(app).label_style,
3211            &widget_state,
3212        );
3213
3214        theme_data
3215            .text_theme
3216            .title_medium
3217            .as_ref()
3218            .expect("the theme's text theme gives titleMedium")
3219            .merge(self.widget(app).base_style.as_ref())
3220            .merge(Some(&default_style))
3221            .merge(style.as_deref())
3222            .copy_with()
3223            .height(1.0)
3224    }
3225
3226    // The base style for the inline hint when they're displayed "inline",
3227    // i.e. when they appear in place of the empty text field.
3228    fn get_inline_hint_style(
3229        self: Handle<Self>,
3230        app: &mut App,
3231        theme_data: &ThemeData,
3232        defaults: &dyn InputDecorationThemeDataGetters,
3233    ) -> TextStyle {
3234        let widget_state = self.widget_state(app);
3235        let default_style = <dyn WidgetStateProperty<TextStyle>>::resolve_as(
3236            defaults
3237                .hint_style(app)
3238                .as_ref()
3239                .expect("the defaults give one"),
3240            &widget_state,
3241        );
3242
3243        let style = <dyn WidgetStateProperty<TextStyle>>::resolve_as(
3244            &self.decoration(app).hint_style,
3245            &widget_state,
3246        );
3247
3248        (if theme_data.use_material3 {
3249            theme_data.text_theme.body_large.as_ref()
3250        } else {
3251            theme_data.text_theme.title_medium.as_ref()
3252        })
3253        .expect("the theme's text theme gives the style")
3254        .merge(self.widget(app).base_style.as_ref())
3255        .merge(Some(&default_style))
3256        .merge(style.as_deref())
3257    }
3258
3259    fn get_floating_label_style(
3260        self: Handle<Self>,
3261        app: &mut App,
3262        theme_data: &ThemeData,
3263        defaults: &dyn InputDecorationThemeDataGetters,
3264    ) -> TextStyle {
3265        let widget_state = self.widget_state(app);
3266        let has_error = self.has_error(app);
3267        let mut default_text_style: TextStyle = <dyn WidgetStateProperty<TextStyle>>::resolve_as(
3268            defaults
3269                .floating_label_style(app)
3270                .as_ref()
3271                .expect("the defaults give one"),
3272            &widget_state,
3273        )
3274        .value()
3275        .clone();
3276        let decoration = self.decoration(app);
3277        if has_error
3278            && let Some(error_color) = decoration
3279                .error_style
3280                .as_ref()
3281                .and_then(|error_style| error_style.color.clone())
3282        {
3283            default_text_style = default_text_style.copy_with().color(error_color);
3284        }
3285        default_text_style = default_text_style.merge(
3286            decoration
3287                .floating_label_style
3288                .as_deref()
3289                .or(decoration.label_style.as_deref()),
3290        );
3291
3292        let style = <dyn WidgetStateProperty<TextStyle>>::resolve_as(
3293            &decoration.floating_label_style,
3294            &widget_state,
3295        );
3296
3297        theme_data
3298            .text_theme
3299            .title_medium
3300            .as_ref()
3301            .expect("the theme's text theme gives titleMedium")
3302            .merge(self.widget(app).base_style.as_ref())
3303            .merge(Some(&default_text_style))
3304            .merge(style.as_deref())
3305            .copy_with()
3306            .height(1.0)
3307    }
3308
3309    fn get_helper_style(
3310        self: Handle<Self>,
3311        app: &mut App,
3312        _theme_data: &ThemeData,
3313        defaults: &dyn InputDecorationThemeDataGetters,
3314    ) -> TextStyle {
3315        let widget_state = self.widget_state(app);
3316        let style = <dyn WidgetStateProperty<TextStyle>>::resolve_as(
3317            &self.decoration(app).helper_style,
3318            &widget_state,
3319        );
3320        <dyn WidgetStateProperty<TextStyle>>::resolve_as(
3321            defaults
3322                .helper_style(app)
3323                .as_ref()
3324                .expect("the defaults give one"),
3325            &widget_state,
3326        )
3327        .merge(style.as_deref())
3328    }
3329
3330    fn get_error_style(
3331        self: Handle<Self>,
3332        app: &mut App,
3333        _theme_data: &ThemeData,
3334        defaults: &dyn InputDecorationThemeDataGetters,
3335    ) -> TextStyle {
3336        let widget_state = self.widget_state(app);
3337        let error_style = self.decoration(app).error_style.clone();
3338        <dyn WidgetStateProperty<TextStyle>>::resolve_as(
3339            defaults
3340                .error_style(app)
3341                .as_ref()
3342                .expect("the defaults give one"),
3343            &widget_state,
3344        )
3345        .merge(error_style.as_deref())
3346    }
3347
3348    fn widget_state(self: Handle<Self>, app: &mut App) -> WidgetStates {
3349        let enabled = self.decoration(app).enabled;
3350        let is_focused = self.is_focused(app);
3351        let is_hovering = self.is_hovering(app);
3352        let has_error = self.has_error(app);
3353        let mut states = WidgetStates::new();
3354        if !enabled {
3355            states.insert(WidgetState::Disabled);
3356        }
3357        if is_focused {
3358            states.insert(WidgetState::Focused);
3359        }
3360        if is_hovering {
3361            states.insert(WidgetState::Hovered);
3362        }
3363        if has_error {
3364            states.insert(WidgetState::Error);
3365        }
3366        states
3367    }
3368
3369    fn get_default_border(
3370        self: Handle<Self>,
3371        app: &mut App,
3372        theme_data: &ThemeData,
3373        defaults: &dyn InputDecorationThemeDataGetters,
3374    ) -> InputBorderRef {
3375        let widget_state = self.widget_state(app);
3376        let decoration = self.decoration(app).clone();
3377        let border: InputBorderRef = <dyn WidgetStateProperty<InputBorderRef>>::resolve_as(
3378            &decoration.border,
3379            &widget_state,
3380        )
3381        .unwrap_or_else(|| InputBorderRef::new(UnderlineInputBorder::new()));
3382
3383        if decoration
3384            .border
3385            .as_ref()
3386            .is_some_and(|border| border.as_widget_state_property().is_some())
3387        {
3388            return border;
3389        }
3390
3391        if border.border_side() == BorderSide::NONE {
3392            return border;
3393        }
3394
3395        if theme_data.use_material3 {
3396            if decoration.filled.expect("applied from the theme") {
3397                let context = self.context(app);
3398                let decoration_theme = InputDecorationTheme::of(app, context);
3399                let active_indicator_border = decoration_theme
3400                    .active_indicator_border
3401                    .clone()
3402                    .or_else(|| defaults.active_indicator_border(app));
3403                InputBorder::copy_with(
3404                    &*border,
3405                    <dyn WidgetStateProperty<Option<BorderSide>>>::resolve_as(
3406                        &active_indicator_border,
3407                        &widget_state,
3408                    )
3409                    .map(|side| *side),
3410                )
3411            } else {
3412                InputBorder::copy_with(
3413                    &*border,
3414                    <dyn WidgetStateProperty<Option<BorderSide>>>::resolve_as(
3415                        &defaults.outline_border(app),
3416                        &widget_state,
3417                    )
3418                    .map(|side| *side),
3419                )
3420            }
3421        } else {
3422            let is_focused = self.is_focused(app);
3423            let color = self.get_default_m2_border_color(app, theme_data);
3424            let width = if decoration.is_collapsed.expect("applied from the theme")
3425                || decoration
3426                    .border
3427                    .as_ref()
3428                    .is_some_and(|border| **border == *InputBorderRef::none())
3429                || !decoration.enabled
3430            {
3431                0.0
3432            } else if is_focused {
3433                2.0
3434            } else {
3435                1.0
3436            };
3437            InputBorder::copy_with(
3438                &*border,
3439                Some(BorderSide {
3440                    color,
3441                    width,
3442                    ..BorderSide::default()
3443                }),
3444            )
3445        }
3446    }
3447
3448    fn build_transition(
3449        self: Handle<Self>,
3450        app: &mut App,
3451        child: &WidgetRef,
3452        animation: AnimationRef<f64>,
3453    ) -> WidgetRef {
3454        let current = app.get(self).curved_animation.handle();
3455        if current.is_none_or(|curved| curved.parent(app) != animation) {
3456            if let Some(curved) = current {
3457                curved.dispose(app);
3458            }
3459            let curved = CurvedAnimation::new(app, animation, k_transition_curve(), None);
3460            app.get_mut(self).curved_animation = Some(curved);
3461        }
3462
3463        let curved = app.get(self).curved_animation.clone().expect("made above");
3464        FadeTransition::new(curved.erase())
3465            .child(child.clone())
3466            .into_widget()
3467    }
3468
3469    fn top_start_layout(
3470        _app: &mut App,
3471        current_child: Option<&WidgetRef>,
3472        previous_children: &[WidgetRef],
3473    ) -> WidgetRef {
3474        Stack::new()
3475            .children(
3476                previous_children
3477                    .iter()
3478                    .cloned()
3479                    .chain(current_child.cloned()),
3480            )
3481            .into_widget()
3482    }
3483}
3484
3485impl TickerProviderStateMixin for InputDecoratorState {
3486    fn ticker_provider_data(self: Handle<Self>, app: &App) -> &TickerProviderStateMixinData {
3487        &app.get(self).ticker_provider
3488    }
3489
3490    fn ticker_provider_data_mut(
3491        self: Handle<Self>,
3492        app: &mut App,
3493    ) -> &mut TickerProviderStateMixinData {
3494        &mut app.get_mut(self).ticker_provider
3495    }
3496}
3497
3498/// Dart's `vsync: this`.
3499impl TickerProviderObject for InputDecoratorState {
3500    fn create_ticker(self: Handle<Self>, app: &mut App, on_tick: TickerCallback) -> Ref<Ticker> {
3501        TickerProviderStateMixin::create_ticker(self, app, on_tick)
3502    }
3503}
3504
3505impl State for InputDecoratorState {
3506    type Widget = InputDecorator;
3507    waft_widgets::state_accessors!();
3508
3509    fn init_state(self: Handle<Self>, app: &mut App) {
3510        let border_gap = InputBorderGap::new(app);
3511        app.get_mut(self).border_gap = Some(border_gap);
3512
3513        let floating_label_controller = AnimationController::new(
3514            app,
3515            None,
3516            Some(K_TRANSITION_DURATION),
3517            None,
3518            0.0,
3519            1.0,
3520            AnimationBehavior::Normal,
3521            self,
3522        );
3523        floating_label_controller
3524            .add_listener(app, Listener::handle_method(self, Self::handle_change));
3525        let floating_label_animation = CurvedAnimation::new(
3526            app,
3527            floating_label_controller.erase(),
3528            k_transition_curve(),
3529            Some(Rc::new(k_transition_curve().flipped())),
3530        );
3531
3532        let shaking_label_controller = AnimationController::new(
3533            app,
3534            None,
3535            Some(K_TRANSITION_DURATION),
3536            None,
3537            0.0,
3538            1.0,
3539            AnimationBehavior::Normal,
3540            self,
3541        );
3542        let state = app.get_mut(self);
3543        state.floating_label_controller = Some(floating_label_controller);
3544        state.floating_label_animation = Some(floating_label_animation);
3545        state.shaking_label_controller = Some(shaking_label_controller);
3546    }
3547
3548    fn did_change_dependencies(self: Handle<Self>, app: &mut App) {
3549        app.get_mut(self).effective_decoration = None;
3550
3551        let label_is_initially_floating = self.decoration(app).floating_label_behavior
3552            != Some(FloatingLabelBehavior::Never)
3553            && self.label_should_withdraw(app);
3554        let floating_label_controller = self.floating_label_controller(app);
3555        floating_label_controller.set_value(
3556            app,
3557            if label_is_initially_floating {
3558                1.0
3559            } else {
3560                0.0
3561            },
3562        );
3563    }
3564
3565    fn activate(self: Handle<Self>, app: &mut App) {
3566        TickerProviderStateMixin::activate(self, app);
3567    }
3568
3569    fn dispose(self: Handle<Self>, app: &mut App) {
3570        let floating_label_controller = self.floating_label_controller(app);
3571        let floating_label_animation = self.floating_label_animation(app);
3572        let shaking_label_controller = self.shaking_label_controller(app);
3573        let border_gap = self.border_gap(app);
3574        let curved_animation = app.get(self).curved_animation.handle();
3575        floating_label_controller.dispose(app);
3576        floating_label_animation.dispose(app);
3577        shaking_label_controller.dispose(app);
3578        ChangeNotifierData::dispose(app, &border_gap);
3579        if let Some(curved_animation) = curved_animation {
3580            curved_animation.dispose(app);
3581        }
3582        TickerProviderStateMixin::dispose(self, app);
3583    }
3584
3585    fn did_update_widget(self: Handle<Self>, app: &mut App, old: &InputDecorator) {
3586        if self.widget(app).decoration != old.decoration {
3587            app.get_mut(self).effective_decoration = None;
3588        }
3589
3590        let widget = self.widget(app);
3591        let float_behavior_changed =
3592            widget.decoration.floating_label_behavior != old.decoration.floating_label_behavior;
3593
3594        if widget.label_should_withdraw() != old.label_should_withdraw() || float_behavior_changed {
3595            let floating_label_controller = self.floating_label_controller(app);
3596            if self.floating_label_enabled(app) && self.label_should_withdraw(app) {
3597                floating_label_controller.forward(app, None);
3598            } else {
3599                floating_label_controller.reverse(app, None);
3600            }
3601        }
3602
3603        let error_text = self.decoration(app).error_text.clone();
3604        let old_error_text = &old.decoration.error_text;
3605
3606        let floating_label_controller = self.floating_label_controller(app);
3607        if floating_label_controller.is_completed(app)
3608            && error_text.is_some()
3609            && error_text != *old_error_text
3610        {
3611            let shaking_label_controller = self.shaking_label_controller(app);
3612            shaking_label_controller.set_value(app, 0.0);
3613            shaking_label_controller.forward(app, None);
3614        }
3615    }
3616
3617    fn build(self: Handle<Self>, app: &mut App, context: BuildContext) -> WidgetRef {
3618        let theme_data = Theme::of(app, context);
3619        let visual_density = self
3620            .decoration(app)
3621            .visual_density
3622            .unwrap_or(theme_data.visual_density);
3623        let use_material3 = Theme::of(app, context).use_material3;
3624        let defaults: Box<dyn InputDecorationThemeDataGetters> = if use_material3 {
3625            Box::new(InputDecoratorDefaultsM3::new(context))
3626        } else {
3627            Box::new(InputDecoratorDefaultsM2::new(context))
3628        };
3629        let icon_button_theme = IconButtonTheme::of(app, context);
3630
3631        let label_style = self.get_inline_label_style(app, &theme_data, &*defaults);
3632        let text_baseline = label_style
3633            .text_baseline
3634            .expect("the label style gives a text baseline");
3635
3636        let hint_style = self.get_inline_hint_style(app, &theme_data, &*defaults);
3637        let is_empty = self.is_empty(app);
3638        let has_inline_label = self.has_inline_label(app);
3639        let text_align = self.text_align(app);
3640        let decoration = self.decoration(app).clone();
3641        let hint_text = decoration.hint_text.clone();
3642        let maintain_hint_size = decoration.maintain_hint_size;
3643        let mut hint: Option<WidgetRef> = None;
3644        if decoration.hint.is_some() || hint_text.is_some() {
3645            let hint_widget = decoration.hint.clone().unwrap_or_else(|| {
3646                let mut text = Text::new(hint_text.clone().expect("a hint or its text is given"))
3647                    .style(hint_style.clone());
3648                if let Some(text_direction) = decoration.hint_text_direction {
3649                    text = text.text_direction(text_direction);
3650                }
3651                let overflow = hint_style
3652                    .overflow
3653                    .or(if decoration.hint_max_lines.is_none() {
3654                        None
3655                    } else {
3656                        Some(TextOverflow::Ellipsis)
3657                    });
3658                if let Some(overflow) = overflow {
3659                    text = text.overflow(overflow);
3660                }
3661                if let Some(text_align) = text_align {
3662                    text = text.text_align(text_align);
3663                }
3664                if let Some(max_lines) = decoration.hint_max_lines {
3665                    text = text.max_lines(max_lines);
3666                }
3667                text.into_widget()
3668            });
3669            let show_hint = is_empty && !has_inline_label;
3670            let hint_fade_duration = decoration
3671                .hint_fade_duration
3672                .unwrap_or(K_HINT_FADE_TRANSITION_DURATION);
3673            hint = Some(if maintain_hint_size {
3674                AnimatedOpacity::new(if show_hint { 1.0 } else { 0.0 }, hint_fade_duration)
3675                    .curve(k_transition_curve())
3676                    .child(hint_widget)
3677                    .into_widget()
3678            } else {
3679                AnimatedSwitcher::new(hint_fade_duration)
3680                    .transition_builder(AnimatedSwitcherTransitionBuilder::handle_method(
3681                        self,
3682                        Self::build_transition,
3683                    ))
3684                    .layout_builder(Self::top_start_layout)
3685                    .child(if show_hint {
3686                        hint_widget
3687                    } else {
3688                        SizedBox::shrink().into_widget()
3689                    })
3690                    .into_widget()
3691            });
3692        }
3693
3694        let is_focused = self.is_focused(app);
3695        let has_error = self.has_error(app);
3696        let mut border: Option<InputBorderRef> = if !decoration.enabled {
3697            if has_error {
3698                decoration.error_border.clone()
3699            } else {
3700                decoration.disabled_border.clone()
3701            }
3702        } else if is_focused {
3703            if has_error {
3704                decoration.focused_error_border.clone()
3705            } else {
3706                decoration.focused_border.clone()
3707            }
3708        } else if has_error {
3709            decoration.error_border.clone()
3710        } else {
3711            decoration.enabled_border.clone()
3712        };
3713        let border = border
3714            .take()
3715            .unwrap_or_else(|| self.get_default_border(app, &theme_data, &*defaults));
3716
3717        let fill_color = self.get_fill_color(app, &theme_data, &*defaults);
3718        let hover_color = self.get_hover_color(app, &theme_data);
3719        let is_hovering = self.is_hovering(app);
3720        let container = BorderContainer {
3721            border: border.clone(),
3722            gap: self.border_gap(app),
3723            gap_animation: self.floating_label_animation(app).erase(),
3724            fill_color,
3725            hover_color,
3726            is_hovering,
3727        }
3728        .into_widget();
3729
3730        let label_should_withdraw = self.label_should_withdraw(app);
3731        let mut label: Option<WidgetRef> = None;
3732        if decoration.label_text.is_some() || decoration.label.is_some() {
3733            let should_show_label = self.should_show_label(app);
3734            let style = if label_should_withdraw {
3735                self.get_floating_label_style(app, &theme_data, &*defaults)
3736            } else {
3737                label_style.clone()
3738            };
3739            let label_child = decoration.label.clone().unwrap_or_else(|| {
3740                let mut text = Text::new(
3741                    decoration
3742                        .label_text
3743                        .clone()
3744                        .expect("a label or its text is given"),
3745                )
3746                .overflow(TextOverflow::Ellipsis);
3747                if let Some(text_align) = text_align {
3748                    text = text.text_align(text_align);
3749                }
3750                if let Some(text_direction) = decoration.label_text_direction {
3751                    text = text.text_direction(text_direction);
3752                }
3753                text.into_widget()
3754            });
3755            let shaking_label_controller = self.shaking_label_controller(app);
3756            label = Some(
3757                MatrixTransition::new(shaking_label_controller.erase(), |value: f64| {
3758                    let shake_offset = if value <= 0.25 {
3759                        -value
3760                    } else if value < 0.75 {
3761                        value - 0.5
3762                    } else {
3763                        (1.0 - value) * 4.0
3764                    };
3765                    // Shakes the floating label to the left and right
3766                    // when the errorText first appears.
3767                    Matrix4::translation((shake_offset * 4.0) as f32, 0.0)
3768                })
3769                .child(
3770                    AnimatedOpacity::new(
3771                        if should_show_label { 1.0 } else { 0.0 },
3772                        K_TRANSITION_DURATION,
3773                    )
3774                    .curve(k_transition_curve())
3775                    .child(
3776                        AnimatedDefaultTextStyle::new(label_child, style, K_TRANSITION_DURATION)
3777                            .curve(k_transition_curve()),
3778                    ),
3779                )
3780                .into_widget(),
3781            );
3782        }
3783
3784        let has_prefix = decoration.prefix.is_some() || decoration.prefix_text.is_some();
3785        let has_suffix = decoration.suffix.is_some() || decoration.suffix_text.is_some();
3786
3787        // `Semantics(sortKey:)` around the input and the sort keys of the affixes, which Dart
3788        // sets when at least two of the three are visible, wait with accessibility.
3789        let input = self.widget(app).child.clone();
3790
3791        let widget_state = self.widget_state(app);
3792        let prefix = has_prefix.then(|| {
3793            AffixText {
3794                label_is_floating: label_should_withdraw,
3795                text: decoration.prefix_text.clone(),
3796                style: Some(
3797                    <dyn WidgetStateProperty<TextStyle>>::resolve_as(
3798                        &decoration.prefix_style,
3799                        &widget_state,
3800                    )
3801                    .map(|style| style.value().clone())
3802                    .unwrap_or_else(|| hint_style.clone()),
3803                ),
3804                child: decoration.prefix.clone(),
3805            }
3806            .into_widget()
3807        });
3808
3809        let suffix = has_suffix.then(|| {
3810            AffixText {
3811                label_is_floating: label_should_withdraw,
3812                text: decoration.suffix_text.clone(),
3813                style: Some(
3814                    <dyn WidgetStateProperty<TextStyle>>::resolve_as(
3815                        &decoration.suffix_style,
3816                        &widget_state,
3817                    )
3818                    .map(|style| style.value().clone())
3819                    .unwrap_or_else(|| hint_style.clone()),
3820                ),
3821                child: decoration.suffix.clone(),
3822            }
3823            .into_widget()
3824        });
3825
3826        let decoration_is_dense = decoration.is_dense.unwrap_or(false);
3827        let icon_size = if decoration_is_dense { 18.0 } else { 24.0 };
3828
3829        let icon = match &decoration.icon {
3830            None => None,
3831            Some(decoration_icon) => {
3832                let icon_color = self.get_icon_color(app, &theme_data, &*defaults);
3833                Some(
3834                    MouseRegion::new()
3835                        .cursor(SystemMouseCursors::BASIC.into())
3836                        .child(
3837                            Padding::new(EdgeInsetsGeometry::directional(0.0, 0.0, 16.0, 0.0))
3838                                .child(IconTheme::merge(
3839                                    None,
3840                                    IconThemeData::new().color(icon_color).size(icon_size),
3841                                    decoration_icon.clone(),
3842                                )),
3843                        )
3844                        .into_widget(),
3845                )
3846            }
3847        };
3848
3849        let prefix_icon = match &decoration.prefix_icon {
3850            None => None,
3851            Some(decoration_prefix_icon) => {
3852                let prefix_icon_color =
3853                    self.get_prefix_icon_color(app, &icon_button_theme, &*defaults);
3854                Some(Self::build_affix_icon(
3855                    decoration_prefix_icon.clone(),
3856                    decoration.prefix_icon_constraints,
3857                    visual_density,
3858                    prefix_icon_color,
3859                    icon_size,
3860                    &icon_button_theme,
3861                ))
3862            }
3863        };
3864
3865        let suffix_icon = match &decoration.suffix_icon {
3866            None => None,
3867            Some(decoration_suffix_icon) => {
3868                let suffix_icon_color =
3869                    self.get_suffix_icon_color(app, &icon_button_theme, &*defaults);
3870                Some(Self::build_affix_icon(
3871                    decoration_suffix_icon.clone(),
3872                    decoration.suffix_icon_constraints,
3873                    visual_density,
3874                    suffix_icon_color,
3875                    icon_size,
3876                    &icon_button_theme,
3877                ))
3878            }
3879        };
3880
3881        let helper_style = self.get_helper_style(app, &theme_data, &*defaults);
3882        let error_style = self.get_error_style(app, &theme_data, &*defaults);
3883        let helper_error = HelperError {
3884            text_align,
3885            helper: decoration.helper.clone(),
3886            helper_text: decoration.helper_text.clone(),
3887            helper_style: Some(helper_style.clone()),
3888            helper_max_lines: decoration.helper_max_lines,
3889            error: decoration.error.clone(),
3890            error_text: decoration.error_text.clone(),
3891            error_style: Some(error_style),
3892            error_max_lines: decoration.error_max_lines,
3893        }
3894        .into_widget();
3895
3896        let mut counter: Option<WidgetRef> = None;
3897        if decoration.counter.is_some() {
3898            counter = decoration.counter.clone();
3899        } else if let Some(counter_text) = decoration
3900            .counter_text
3901            .as_ref()
3902            .filter(|counter_text| !counter_text.is_empty())
3903        {
3904            // `Semantics(container:, liveRegion:)` and the counter's `semanticsLabel`
3905            // (`semantic_counter_text`) wait with accessibility.
3906            let counter_style = <dyn WidgetStateProperty<TextStyle>>::resolve_as(
3907                &decoration.counter_style,
3908                &widget_state,
3909            );
3910            counter = Some(
3911                Text::new(counter_text.clone())
3912                    .style(helper_style.merge(counter_style.as_deref()))
3913                    .overflow(TextOverflow::Ellipsis)
3914                    .into_widget(),
3915            );
3916        }
3917
3918        // The _Decoration widget and _RenderDecoration assume that contentPadding
3919        // has been resolved to EdgeInsets.
3920        let text_direction = Directionality::of(app, context);
3921        let flip_horizontal = match text_direction {
3922            TextDirection::Ltr => false,
3923            TextDirection::Rtl => true,
3924        };
3925        let resolved_padding = decoration
3926            .content_padding
3927            .map(|padding| padding.resolve(Some(text_direction)));
3928        let decoration_content_padding = resolved_padding.map(|resolved_padding| {
3929            EdgeInsetsDirectional::from_steb(
3930                if flip_horizontal {
3931                    resolved_padding.right
3932                } else {
3933                    resolved_padding.left
3934                },
3935                resolved_padding.top,
3936                if flip_horizontal {
3937                    resolved_padding.left
3938                } else {
3939                    resolved_padding.right
3940                },
3941                resolved_padding.bottom,
3942            )
3943        });
3944
3945        let resolved_supporting_text_padding = decoration
3946            .supporting_text_padding
3947            .map(|padding| padding.resolve(Some(text_direction)));
3948        let decoration_supporting_text_padding =
3949            resolved_supporting_text_padding.map(|resolved_supporting_text_padding| {
3950                EdgeInsetsDirectional::from_steb(
3951                    if flip_horizontal {
3952                        resolved_supporting_text_padding.right
3953                    } else {
3954                        resolved_supporting_text_padding.left
3955                    },
3956                    resolved_supporting_text_padding.top,
3957                    if flip_horizontal {
3958                        resolved_supporting_text_padding.left
3959                    } else {
3960                        resolved_supporting_text_padding.right
3961                    },
3962                    resolved_supporting_text_padding.bottom,
3963                )
3964            });
3965
3966        let content_padding: EdgeInsetsDirectional;
3967        let floating_label_height: f64;
3968
3969        if decoration.is_collapsed.expect("applied from the theme") {
3970            floating_label_height = 0.0;
3971            content_padding = decoration_content_padding.unwrap_or(EdgeInsetsDirectional::ZERO);
3972        } else if !border.is_outline() {
3973            // 4.0: the vertical gap between the inline elements and the floating label.
3974            floating_label_height = MediaQuery::text_scaler_of(app, context).scale(
3975                4.0 + 0.75
3976                    * label_style
3977                        .font_size
3978                        .expect("the label style gives a font size"),
3979            );
3980            if decoration.filled.unwrap_or(false) {
3981                content_padding = decoration_content_padding.unwrap_or(if use_material3 {
3982                    if decoration_is_dense {
3983                        EdgeInsetsDirectional::from_steb(12.0, 4.0, 12.0, 4.0)
3984                    } else {
3985                        EdgeInsetsDirectional::from_steb(12.0, 8.0, 12.0, 8.0)
3986                    }
3987                } else if decoration_is_dense {
3988                    EdgeInsetsDirectional::from_steb(12.0, 8.0, 12.0, 8.0)
3989                } else {
3990                    EdgeInsetsDirectional::from_steb(12.0, 12.0, 12.0, 12.0)
3991                });
3992            } else {
3993                // No left or right padding for underline borders that aren't filled
3994                // is a small concession to backwards compatibility. This eliminates
3995                // the most noticeable layout change introduced by #13734.
3996                content_padding = decoration_content_padding.unwrap_or(if use_material3 {
3997                    if decoration_is_dense {
3998                        EdgeInsetsDirectional::from_steb(0.0, 4.0, 0.0, 4.0)
3999                    } else {
4000                        EdgeInsetsDirectional::from_steb(0.0, 8.0, 0.0, 8.0)
4001                    }
4002                } else if decoration_is_dense {
4003                    EdgeInsetsDirectional::from_steb(0.0, 8.0, 0.0, 8.0)
4004                } else {
4005                    EdgeInsetsDirectional::from_steb(0.0, 12.0, 0.0, 12.0)
4006                });
4007            }
4008        } else {
4009            floating_label_height = 0.0;
4010            content_padding = decoration_content_padding.unwrap_or(if use_material3 {
4011                if decoration_is_dense {
4012                    EdgeInsetsDirectional::from_steb(12.0, 16.0, 12.0, 8.0)
4013                } else {
4014                    EdgeInsetsDirectional::from_steb(12.0, 20.0, 12.0, 12.0)
4015                }
4016            } else if decoration_is_dense {
4017                EdgeInsetsDirectional::from_steb(12.0, 20.0, 12.0, 12.0)
4018            } else {
4019                EdgeInsetsDirectional::from_steb(12.0, 24.0, 12.0, 16.0)
4020            });
4021        }
4022
4023        let mut input_gap = 0.0;
4024        if use_material3 {
4025            if let Some(outline) = border.as_any().downcast_ref::<OutlineInputBorder>() {
4026                input_gap = outline.gap_padding;
4027            } else {
4028                input_gap = if border.is_outline() || decoration.filled.unwrap_or(false) {
4029                    K_INPUT_EXTRA_PADDING
4030                } else {
4031                    0.0
4032                };
4033            }
4034        }
4035
4036        let floating_label_progress = self.floating_label_animation(app).value(app);
4037        let border_gap = self.border_gap(app);
4038        let decorator = Decorator {
4039            decoration: Decoration {
4040                content_padding,
4041                is_collapsed: decoration.is_collapsed.expect("applied from the theme"),
4042                input_gap,
4043                floating_label_height,
4044                floating_label_alignment: decoration
4045                    .floating_label_alignment
4046                    .expect("applied from the theme"),
4047                floating_label_progress,
4048                border,
4049                border_gap,
4050                align_label_with_hint: decoration.align_label_with_hint.unwrap_or(false),
4051                is_dense: decoration.is_dense,
4052                is_empty,
4053                visual_density,
4054                maintain_hint_size,
4055                maintain_label_size: decoration.maintain_label_size,
4056                icon,
4057                input,
4058                label,
4059                hint,
4060                prefix,
4061                suffix,
4062                prefix_icon,
4063                suffix_icon,
4064                helper_error: Some(helper_error),
4065                counter,
4066                container: Some(container),
4067                supporting_text_padding: decoration_supporting_text_padding,
4068            },
4069            text_direction,
4070            text_baseline,
4071            text_align_vertical: self.widget(app).text_align_vertical,
4072            is_focused,
4073            expands: self.widget(app).expands,
4074        };
4075
4076        // `Semantics(hint: decoration.errorText)` around the decorator waits with
4077        // accessibility.
4078        let result = decorator.into_widget();
4079
4080        if let Some(constraints) = decoration.constraints {
4081            return ConstrainedBox::new(constraints).child(result).into_widget();
4082        }
4083        result
4084    }
4085}
4086
4087impl InputDecoratorState {
4088    /// The `prefixIcon` and `suffixIcon` widgets of Dart's `build`, which differ only in their
4089    /// icon, constraints and colour.
4090    fn build_affix_icon(
4091        affix_icon: WidgetRef,
4092        constraints: Option<BoxConstraints>,
4093        visual_density: VisualDensity,
4094        color: Color,
4095        icon_size: f64,
4096        icon_button_theme: &IconButtonThemeData,
4097    ) -> WidgetRef {
4098        // `Semantics(tagForChildren:)` around the icon waits with accessibility.
4099        Center::new()
4100            .width_factor(1.0)
4101            .height_factor(1.0)
4102            .child(
4103                MouseRegion::new()
4104                    .cursor(SystemMouseCursors::BASIC.into())
4105                    .child(
4106                        ConstrainedBox::new(constraints.unwrap_or_else(|| {
4107                            visual_density.effective_constraints(BoxConstraints {
4108                                min_width: K_MIN_INTERACTIVE_DIMENSION,
4109                                min_height: K_MIN_INTERACTIVE_DIMENSION,
4110                                ..BoxConstraints::new()
4111                            })
4112                        }))
4113                        .child(IconTheme::merge(
4114                            None,
4115                            IconThemeData::new().color(color).size(icon_size),
4116                            IconButtonTheme::new(
4117                                IconButtonThemeData::new().style(
4118                                    ButtonStyle::new()
4119                                        .foreground_color(Rc::new(WidgetStatePropertyAll::new(
4120                                            Some(color),
4121                                        ))
4122                                            as WidgetStatePropertyRef<Option<Color>>)
4123                                        .icon_size(Rc::new(WidgetStatePropertyAll::new(Some(
4124                                            icon_size,
4125                                        )))
4126                                            as WidgetStatePropertyRef<Option<f64>>)
4127                                        .merge(icon_button_theme.style.as_ref()),
4128                                ),
4129                                affix_icon,
4130                            ),
4131                        )),
4132                    ),
4133            )
4134            .into_widget()
4135    }
4136}
4137
4138impl Debug for InputDecoratorState {
4139    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4140        f.debug_struct("_InputDecoratorState")
4141            .field("floating_label_controller", &self.floating_label_controller)
4142            .finish_non_exhaustive()
4143    }
4144}
4145
4146/// The border, labels, icons, and styles used to decorate a Material
4147/// Design text field.
4148///
4149/// The `TextField` and `InputDecorator` classes use `InputDecoration` objects
4150/// to describe their decoration. (In fact, this class is merely the
4151/// configuration of an `InputDecorator`, which does all the heavy lifting.)
4152///
4153/// See also:
4154///
4155///  * `TextField`, which is a text input widget that uses an
4156///    `InputDecoration`.
4157///  * `InputDecorator`, which is a widget that draws an `InputDecoration`
4158///    around an input child widget.
4159///  * `Decoration` and `DecoratedBox`, for drawing borders and backgrounds
4160///    around a child widget.
4161///
4162/// Dart's two constructors are [`new`](Self::new) and [`collapsed`](Self::collapsed), and
4163/// their named arguments the fluent setters, which every decoration has. Dart's constructor
4164/// asserts that relate two arguments run in `debug_check_arguments`, which `InputDecorator`
4165/// calls when it is turned into a `WidgetRef` (`into_widget`).
4166#[derive(Clone)]
4167pub struct InputDecoration {
4168    /// An icon to show before the input field and outside of the decoration's
4169    /// container.
4170    ///
4171    /// The size and color of the icon is configured automatically using an
4172    /// `IconTheme` and therefore does not need to be explicitly given in the
4173    /// icon widget.
4174    ///
4175    /// The trailing edge of the icon is padded by 16dps.
4176    ///
4177    /// The decoration's container is the area which is filled if `filled` is
4178    /// true and bordered per the `border`. It's the area adjacent to
4179    /// `icon` and above the widgets that contain `helper_text`,
4180    /// `error_text`, and `counter_text`.
4181    ///
4182    /// See `Icon`, `ImageIcon`.
4183    pub icon: Option<WidgetRef>,
4184
4185    /// The color of the `icon`.
4186    ///
4187    /// If `icon_color` is a `WidgetStateColor`, then the effective
4188    /// color can depend on the `WidgetState::Focused` state, i.e.
4189    /// if the `TextField` is focused or not.
4190    pub icon_color: Option<AnyColor>,
4191
4192    /// Optional widget that describes the input field.
4193    ///
4194    /// When the input field is empty and unfocused, the label is displayed on
4195    /// top of the input field (i.e., at the same location on the screen where
4196    /// text may be entered in the input field). When the input field receives
4197    /// focus (or if the field is non-empty), depending on `floating_label_alignment`,
4198    /// the label moves above, either vertically adjacent to, or to the center of
4199    /// the input field.
4200    ///
4201    /// This can be used, for example, to add multiple `TextStyle`'s to a label that would
4202    /// otherwise be specified using `label_text`, which only takes one `TextStyle`.
4203    ///
4204    /// Only one of `label` and `label_text` can be specified.
4205    pub label: Option<WidgetRef>,
4206
4207    /// Optional text that describes the input field.
4208    ///
4209    /// When the input field is empty and unfocused, the label is displayed on
4210    /// top of the input field (i.e., at the same location on the screen where
4211    /// text may be entered in the input field). When the input field receives
4212    /// focus (or if the field is non-empty), depending on `floating_label_alignment`,
4213    /// the label moves above, either vertically adjacent to, or to the center of
4214    /// the input field.
4215    ///
4216    /// If a more elaborate label is required, consider using `label` instead.
4217    /// Only one of `label` and `label_text` can be specified.
4218    pub label_text: Option<String>,
4219
4220    /// The style to use for `InputDecoration::label_text` when the label is on top
4221    /// of the input field.
4222    ///
4223    /// If `label_style` is a `WidgetStateTextStyle`, then the effective
4224    /// text style can depend on the `WidgetState::Focused` state, i.e.
4225    /// if the `TextField` is focused or not.
4226    ///
4227    /// When the `InputDecoration::label_text` is above (i.e., vertically adjacent to)
4228    /// the input field, the text uses the `floating_label_style` instead.
4229    ///
4230    /// If null, defaults to a value derived from the base `TextStyle` for the
4231    /// input field and the current `Theme`.
4232    ///
4233    /// Specifying this style will override the default behavior
4234    /// of `InputDecoration` that changes the color of the label to the
4235    /// `InputDecoration::error_style` color or `ColorScheme::error`.
4236    pub label_style: Option<AnyTextStyle>,
4237
4238    /// The style to use for `InputDecoration::label_text` when the label is
4239    /// above (i.e., vertically adjacent to) the input field.
4240    ///
4241    /// When the `InputDecoration::label_text` is on top of the input field, the
4242    /// text uses the `label_style` instead.
4243    ///
4244    /// If `floating_label_style` is a `WidgetStateTextStyle`, then the effective
4245    /// text style can depend on the `WidgetState::Focused` state, i.e.
4246    /// if the `TextField` is focused or not.
4247    ///
4248    /// If null, defaults to `label_style`.
4249    ///
4250    /// Specifying this style will override the default behavior
4251    /// of `InputDecoration` that changes the color of the label to the
4252    /// `InputDecoration::error_style` color or `ColorScheme::error`.
4253    ///
4254    /// When the input field receives focus, the font size of `InputDecoration::label` is
4255    /// scaled down by 75%.
4256    pub floating_label_style: Option<AnyTextStyle>,
4257
4258    /// The direction to use for the `label_text`.
4259    ///
4260    /// If null, defaults to a value derived from `Directionality` for the
4261    /// input field and the current context.
4262    ///
4263    /// This is ignored if `label` is provided instead of `label_text`.
4264    /// If you need to set the direction for a custom `label` widget,
4265    /// wrap that widget in a `Directionality` widget or use a `Text`
4266    /// widget with its own `Text::text_direction` property.
4267    pub label_text_direction: Option<TextDirection>,
4268
4269    /// Optional widget that appears below the `InputDecorator::child`.
4270    ///
4271    /// If non-null, the `helper` is displayed below the `InputDecorator::child`, in
4272    /// the same location as `error`. If a non-null `error` or `error_text` value is
4273    /// specified then the `helper` is not shown.
4274    ///
4275    /// Only one of `helper` and `helper_text` can be specified.
4276    pub helper: Option<WidgetRef>,
4277
4278    /// Text that provides context about the `InputDecorator::child`'s value, such
4279    /// as how the value will be used.
4280    ///
4281    /// If non-null, the text is displayed below the `InputDecorator::child`, in
4282    /// the same location as `error_text`. If a non-null `error_text` value is
4283    /// specified then the helper text is not shown.
4284    ///
4285    /// If a more elaborate helper text is required, consider using `helper` instead.
4286    ///
4287    /// Only one of `helper` and `helper_text` can be specified.
4288    pub helper_text: Option<String>,
4289
4290    /// The style to use for the `helper_text`.
4291    ///
4292    /// If `helper_style` is a `WidgetStateTextStyle`, then the effective
4293    /// text style can depend on the `WidgetState::Focused` state, i.e.
4294    /// if the `TextField` is focused or not.
4295    pub helper_style: Option<AnyTextStyle>,
4296
4297    /// The maximum number of lines the `helper_text` can occupy.
4298    ///
4299    /// Defaults to null, which means that soft line breaks in `helper_text` are
4300    /// truncated with an ellipse while hard line breaks are respected.
4301    /// For example, a `helper_text` that overflows the width of the field will be
4302    /// truncated with an ellipse. However, a `helper_text` with explicit linebreak
4303    /// characters (\n) will display on multiple lines.
4304    ///
4305    /// To cause a long `helper_text` to wrap, either set `helper_max_lines` or use
4306    /// `helper` which offers more flexibility. For instance, it can be set to a
4307    /// `Text` widget with a specific overflow value.
4308    ///
4309    /// This value is passed along to the `Text::max_lines` attribute
4310    /// of the `Text` widget used to display the helper.
4311    ///
4312    /// See also:
4313    ///
4314    ///  * `error_max_lines`, the equivalent but for the `error_text`.
4315    pub helper_max_lines: Option<i32>,
4316
4317    /// Text that suggests what sort of input the field accepts.
4318    ///
4319    /// Displayed on top of the `InputDecorator::child` (i.e., at the same location
4320    /// on the screen where text may be entered in the `InputDecorator::child`),
4321    /// when `InputDecorator::is_empty` is true and either (a) `label_text` is null
4322    /// or (b) the input has the focus.
4323    pub hint_text: Option<String>,
4324
4325    /// The widget to use in place of the `hint_text`.
4326    ///
4327    /// Either `hint_text` or `hint` can be specified, but not both.
4328    pub hint: Option<WidgetRef>,
4329
4330    /// The style to use for the `hint_text`.
4331    ///
4332    /// If `hint_style` is a `WidgetStateTextStyle`, then the effective
4333    /// text style can depend on the `WidgetState::Focused` state, i.e.
4334    /// if the `TextField` is focused or not.
4335    ///
4336    /// Also used for the `label_text` when the `label_text` is displayed on
4337    /// top of the input field (i.e., at the same location on the screen where
4338    /// text may be entered in the `InputDecorator::child`).
4339    ///
4340    /// If null, defaults to a value derived from the base `TextStyle` for the
4341    /// input field and the current `Theme`.
4342    pub hint_style: Option<AnyTextStyle>,
4343
4344    /// The direction to use for the `hint_text`.
4345    ///
4346    /// If null, defaults to a value derived from `Directionality` for the
4347    /// input field and the current context.
4348    ///
4349    /// This is ignored if `hint` is provided instead of `hint_text`.
4350    /// If you need to set the direction for a custom `hint` widget,
4351    /// wrap that widget in a `Directionality` widget or use a `Text`
4352    /// widget with its own `Text::text_direction` property.
4353    pub hint_text_direction: Option<TextDirection>,
4354
4355    /// The maximum number of lines the `hint_text` can occupy.
4356    ///
4357    /// Defaults to the value of `TextField::max_lines` attribute.
4358    ///
4359    /// This value is passed along to the `Text::max_lines` attribute
4360    /// of the `Text` widget used to display the hint text. `TextOverflow::Ellipsis` is
4361    /// used to handle the overflow when it is limited to single line.
4362    pub hint_max_lines: Option<i32>,
4363
4364    /// The duration of the `hint_text` fade in and fade out animations.
4365    ///
4366    /// If null, defaults to `InputDecorationThemeData::hint_fade_duration`.
4367    /// If `InputDecorationThemeData::hint_fade_duration` is null defaults to 20ms.
4368    pub hint_fade_duration: Option<Duration>,
4369
4370    /// Whether the input field's height should always be greater than or equal to
4371    /// the height of the `hint_text`, even if the `hint_text` is not visible.
4372    ///
4373    /// The `InputDecorator` widget ignores `hint_text` during layout when
4374    /// it's not visible, if this flag is set to false.
4375    ///
4376    /// Defaults to true.
4377    #[deprecated(
4378        note = "Use maintainHintSize instead. This will maintain both hint height and hint width. This feature was deprecated after v3.28.0-2.0.pre."
4379    )]
4380    pub maintain_hint_height: bool,
4381
4382    /// Whether the input field's size should always be greater than or equal to
4383    /// the size of the `hint` or `hint_text`, even if the `hint` or `hint_text` are not visible.
4384    ///
4385    /// The `InputDecorator` widget ignores `hint` and `hint_text` during layout when
4386    /// they are not visible, if this flag is set to false.
4387    ///
4388    /// Defaults to true.
4389    pub maintain_hint_size: bool,
4390
4391    /// Whether the input field's size should always be greater than or equal to
4392    /// the size of the `label` or `label_text`, even if the `label` or `label_text` are not visible.
4393    ///
4394    /// The `InputDecorator` widget ignores `label` and `label_text` during layout when
4395    /// this flag is set to false.
4396    ///
4397    /// Defaults to false for compatibility reason.
4398    pub maintain_label_size: bool,
4399
4400    /// Optional widget that appears below the `InputDecorator::child` and the border.
4401    ///
4402    /// If non-null, the border's color animates to red and the `helper_text` is not shown.
4403    ///
4404    /// Only one of `error` and `error_text` can be specified.
4405    pub error: Option<WidgetRef>,
4406
4407    /// Text that appears below the `InputDecorator::child` and the border.
4408    ///
4409    /// If non-null, the border's color animates to red and the `helper_text` is
4410    /// not shown.
4411    ///
4412    /// In a `TextFormField`, this is overridden by the value returned from
4413    /// `TextFormField::validator`, if that is not null.
4414    ///
4415    /// If a more elaborate error is required, consider using `error` instead.
4416    ///
4417    /// Only one of `error` and `error_text` can be specified.
4418    pub error_text: Option<String>,
4419
4420    /// The style to use for the `InputDecoration::error_text`.
4421    ///
4422    /// If null, defaults of a value derived from the base `TextStyle` for the
4423    /// input field and the current `Theme`.
4424    ///
4425    /// By default the color of style will be used by the label of
4426    /// `InputDecoration` if `InputDecoration::error_text` is not null. See
4427    /// `InputDecoration::label_style` or `InputDecoration::floating_label_style` for
4428    /// an example of how to replicate this behavior when specifying those
4429    /// styles.
4430    pub error_style: Option<AnyTextStyle>,
4431
4432    /// The maximum number of lines the `error_text` can occupy.
4433    ///
4434    /// Defaults to null, which means that soft line breaks in `error_text` are
4435    /// truncated with an ellipse while hard line breaks are respected.
4436    /// For example, an `error_text` that overflows the width of the field will be
4437    /// truncated with an ellipse. However, an `error_text` with explicit linebreak
4438    /// characters (\n) will display on multiple lines.
4439    ///
4440    /// To cause a long `error_text` to wrap, either set `error_max_lines` or use
4441    /// `error` which offers more flexibility. For instance, it can be set to a
4442    /// `Text` widget with a specific overflow value.
4443    ///
4444    /// This value is passed along to the `Text::max_lines` attribute
4445    /// of the `Text` widget used to display the error.
4446    ///
4447    /// See also:
4448    ///
4449    ///  * `helper_max_lines`, the equivalent but for the `helper_text`.
4450    pub error_max_lines: Option<i32>,
4451
4452    /// Defines **how** the floating label should behave.
4453    ///
4454    /// When `FloatingLabelBehavior::Auto` the label will float to the top only when
4455    /// the field is focused or has some text content, otherwise it will appear
4456    /// in the field in place of the content.
4457    ///
4458    /// When `FloatingLabelBehavior::Always` the label will always float at the top
4459    /// of the field above the content.
4460    ///
4461    /// When `FloatingLabelBehavior::Never` the label will always appear in an empty
4462    /// field in place of the content.
4463    ///
4464    /// If null, `InputDecorationThemeData::floating_label_behavior` will be used.
4465    ///
4466    /// See also:
4467    ///
4468    ///  * `floating_label_alignment` which defines **where** the floating label
4469    ///    should be displayed.
4470    pub floating_label_behavior: Option<FloatingLabelBehavior>,
4471
4472    /// Defines **where** the floating label should be displayed.
4473    ///
4474    /// `FloatingLabelAlignment::START` aligns the floating label to the leftmost
4475    /// (when `TextDirection::Ltr`) or rightmost (when `TextDirection::Rtl`),
4476    /// possible position, which is vertically adjacent to the label, on top of
4477    /// the field.
4478    ///
4479    /// `FloatingLabelAlignment::CENTER` aligns the floating label to the center on
4480    /// top of the field.
4481    ///
4482    /// If null, `InputDecorationThemeData::floating_label_alignment` will be used.
4483    ///
4484    /// See also:
4485    ///
4486    ///  * `floating_label_behavior` which defines **how** the floating label should
4487    ///    behave.
4488    pub floating_label_alignment: Option<FloatingLabelAlignment>,
4489
4490    /// Whether the `InputDecorator::child` is part of a dense form (i.e., uses less vertical
4491    /// space).
4492    ///
4493    /// Defaults to false.
4494    pub is_dense: Option<bool>,
4495
4496    /// The padding for the input decoration's container.
4497    ///
4498    /// The decoration's container is the area which is filled if `filled` is true
4499    /// and bordered per the `border`. It's the area adjacent to `icon` and above
4500    /// the widgets that contain `helper_text`, `error_text`, and `counter_text`.
4501    ///
4502    /// By default the `content_padding` reflects `is_dense` and the type of the
4503    /// `border`.
4504    ///
4505    /// If `is_collapsed` is true then `content_padding` is `EdgeInsets::ZERO`.
4506    ///
4507    /// ### Material 3 default content padding
4508    ///
4509    /// If `isOutline` property of `border` is false and if `filled` is true then
4510    /// `content_padding` is `EdgeInsets.fromLTRB(12, 4, 12, 4)` when `is_dense`
4511    /// is true and `EdgeInsets.fromLTRB(12, 8, 12, 8)` when `is_dense` is false.
4512    ///
4513    /// If `isOutline` property of `border` is false and if `filled` is false then
4514    /// `content_padding` is `EdgeInsets.fromLTRB(0, 4, 0, 4)` when `is_dense` is
4515    /// true and `EdgeInsets.fromLTRB(0, 8, 0, 8)` when `is_dense` is false.
4516    ///
4517    /// If `isOutline` property of `border` is true then `content_padding` is
4518    /// `EdgeInsets.fromLTRB(12, 16, 12, 8)` when `is_dense` is true
4519    /// and `EdgeInsets.fromLTRB(12, 20, 12, 12)` when `is_dense` is false.
4520    ///
4521    /// ### Material 2 default content padding
4522    ///
4523    /// If `isOutline` property of `border` is false and if `filled` is true then
4524    /// `content_padding` is `EdgeInsets.fromLTRB(12, 8, 12, 8)` when `is_dense`
4525    /// is true and `EdgeInsets.fromLTRB(12, 12, 12, 12)` when `is_dense` is false.
4526    ///
4527    /// If `isOutline` property of `border` is false and if `filled` is false then
4528    /// `content_padding` is `EdgeInsets.fromLTRB(0, 8, 0, 8)` when `is_dense` is
4529    /// true and `EdgeInsets.fromLTRB(0, 12, 0, 12)` when `is_dense` is false.
4530    ///
4531    /// If `isOutline` property of `border` is true then `content_padding` is
4532    /// `EdgeInsets.fromLTRB(12, 20, 12, 12)` when `is_dense` is true
4533    /// and `EdgeInsets.fromLTRB(12, 24, 12, 16)` when `is_dense` is false.
4534    pub content_padding: Option<EdgeInsetsGeometry>,
4535
4536    /// Whether the decoration is the same size as the input field.
4537    ///
4538    /// A collapsed decoration cannot have `label_text`, `error_text`, `counter`,
4539    /// `icon`, prefixes, and suffixes.
4540    ///
4541    /// To create a collapsed input decoration, use `InputDecoration::collapsed`.
4542    pub is_collapsed: Option<bool>,
4543
4544    /// An icon that appears before the `prefix` or `prefix_text` and before
4545    /// the editable part of the text field, within the decoration's container.
4546    ///
4547    /// The size and color of the prefix icon is configured automatically using an
4548    /// `IconTheme` and therefore does not need to be explicitly given in the
4549    /// icon widget.
4550    ///
4551    /// The prefix icon is constrained with a minimum size of 48px by 48px, but
4552    /// can be expanded beyond that. Anything larger than 24px will require
4553    /// additional padding to ensure it matches the Material Design spec of 12px
4554    /// padding between the left edge of the input and leading edge of the prefix
4555    /// icon. The following snippet shows how to pad the leading edge of the
4556    /// prefix icon:
4557    ///
4558    /// ```text
4559    /// prefixIcon: Padding(
4560    ///   padding: const EdgeInsetsDirectional.only(start: 12.0),
4561    ///   child: _myIcon, // _myIcon is a 48px-wide widget.
4562    /// )
4563    /// ```
4564    ///
4565    /// The decoration's container is the area which is filled if `filled` is true
4566    /// and bordered per the `border`. It's the area adjacent to `icon` and above
4567    /// the widgets that contain `helper_text`, `error_text`, and `counter_text`.
4568    ///
4569    /// The prefix icon alignment can be changed using `Align` with a fixed `widthFactor` and
4570    /// `heightFactor`.
4571    ///
4572    /// See also:
4573    ///
4574    ///  * `Icon` and `ImageIcon`, which are typically used to show icons.
4575    ///  * `prefix` and `prefix_text`, which are other ways to show content
4576    ///    before the text field (but after the icon).
4577    ///  * `suffix_icon`, which is the same but on the trailing edge.
4578    ///  * `Align` A widget that aligns its child within itself and optionally
4579    ///    sizes itself based on the child's size.
4580    pub prefix_icon: Option<WidgetRef>,
4581
4582    /// The constraints for the prefix icon.
4583    ///
4584    /// This can be used to modify the `BoxConstraints` surrounding `prefix_icon`.
4585    ///
4586    /// This property is particularly useful for getting the decoration's height
4587    /// less than the minimum tappable height (which is 48px when the visual
4588    /// density is set to `VisualDensity::standard`). This can be achieved by
4589    /// setting `is_dense` to true and setting the constraints' minimum height
4590    /// and width to a value lower than the minimum tappable size.
4591    pub prefix_icon_constraints: Option<BoxConstraints>,
4592
4593    /// Optional widget to place on the line before the input.
4594    ///
4595    /// This can be used, for example, to add some padding to text that would
4596    /// otherwise be specified using `prefix_text`, or to add a custom widget in
4597    /// front of the input. The widget's baseline is lined up with the input
4598    /// baseline.
4599    ///
4600    /// Only one of `prefix` and `prefix_text` can be specified.
4601    ///
4602    /// The `prefix` appears after the `prefix_icon`, if both are specified.
4603    ///
4604    /// See also:
4605    ///
4606    ///  * `suffix`, the equivalent but on the trailing edge.
4607    pub prefix: Option<WidgetRef>,
4608
4609    /// Optional text prefix to place on the line before the input.
4610    ///
4611    /// Uses the `prefix_style`. Uses `hint_style` if `prefix_style` isn't specified.
4612    /// The prefix text is not returned as part of the user's input.
4613    ///
4614    /// If a more elaborate prefix is required, consider using `prefix` instead.
4615    /// Only one of `prefix` and `prefix_text` can be specified.
4616    ///
4617    /// The `prefix_text` appears after the `prefix_icon`, if both are specified.
4618    ///
4619    /// See also:
4620    ///
4621    ///  * `suffix_text`, the equivalent but on the trailing edge.
4622    pub prefix_text: Option<String>,
4623
4624    /// The style to use for the `prefix_text`.
4625    ///
4626    /// If `prefix_style` is a `WidgetStateTextStyle`, then the effective
4627    /// text style can depend on the `WidgetState::Focused` state, i.e.
4628    /// if the `TextField` is focused or not.
4629    ///
4630    /// If null, defaults to the `hint_style`.
4631    ///
4632    /// See also:
4633    ///
4634    ///  * `suffix_style`, the equivalent but on the trailing edge.
4635    pub prefix_style: Option<AnyTextStyle>,
4636
4637    /// Optional color of the prefixIcon
4638    ///
4639    /// Defaults to `icon_color`
4640    ///
4641    /// If `prefix_icon_color` is a `WidgetStateColor`, then the effective
4642    /// color can depend on the `WidgetState::Focused` state, i.e.
4643    /// if the `TextField` is focused or not.
4644    pub prefix_icon_color: Option<AnyColor>,
4645
4646    /// An icon that appears after the editable part of the text field and
4647    /// after the `suffix` or `suffix_text`, within the decoration's container.
4648    ///
4649    /// The size and color of the suffix icon is configured automatically using an
4650    /// `IconTheme` and therefore does not need to be explicitly given in the
4651    /// icon widget.
4652    ///
4653    /// The suffix icon is constrained with a minimum size of 48px by 48px, but
4654    /// can be expanded beyond that. Anything larger than 24px will require
4655    /// additional padding to ensure it matches the Material Design spec of 12px
4656    /// padding between the right edge of the input and trailing edge of the
4657    /// prefix icon. The following snippet shows how to pad the trailing edge of
4658    /// the suffix icon:
4659    ///
4660    /// ```text
4661    /// suffixIcon: Padding(
4662    ///   padding: const EdgeInsetsDirectional.only(end: 12.0),
4663    ///   child: _myIcon, // myIcon is a 48px-wide widget.
4664    /// )
4665    /// ```
4666    ///
4667    /// The decoration's container is the area which is filled if `filled` is
4668    /// true and bordered per the `border`. It's the area adjacent to
4669    /// `icon` and above the widgets that contain `helper_text`,
4670    /// `error_text`, and `counter_text`.
4671    ///
4672    /// The suffix icon alignment can be changed using `Align` with a fixed `widthFactor` and
4673    /// `heightFactor`.
4674    ///
4675    /// See also:
4676    ///
4677    ///  * `Icon` and `ImageIcon`, which are typically used to show icons.
4678    ///  * `suffix` and `suffix_text`, which are other ways to show content
4679    ///    after the text field (but before the icon).
4680    ///  * `prefix_icon`, which is the same but on the leading edge.
4681    ///  * `Align` A widget that aligns its child within itself and optionally
4682    ///    sizes itself based on the child's size.
4683    pub suffix_icon: Option<WidgetRef>,
4684
4685    /// Optional widget to place on the line after the input.
4686    ///
4687    /// This can be used, for example, to add some padding to the text that would
4688    /// otherwise be specified using `suffix_text`, or to add a custom widget after
4689    /// the input. The widget's baseline is lined up with the input baseline.
4690    ///
4691    /// Only one of `suffix` and `suffix_text` can be specified.
4692    ///
4693    /// The `suffix` appears before the `suffix_icon`, if both are specified.
4694    ///
4695    /// See also:
4696    ///
4697    ///  * `prefix`, the equivalent but on the leading edge.
4698    pub suffix: Option<WidgetRef>,
4699
4700    /// Optional text suffix to place on the line after the input.
4701    ///
4702    /// Uses the `suffix_style`. Uses `hint_style` if `suffix_style` isn't specified.
4703    /// The suffix text is not returned as part of the user's input.
4704    ///
4705    /// If a more elaborate suffix is required, consider using `suffix` instead.
4706    /// Only one of `suffix` and `suffix_text` can be specified.
4707    ///
4708    /// The `suffix_text` appears before the `suffix_icon`, if both are specified.
4709    ///
4710    /// See also:
4711    ///
4712    ///  * `prefix_text`, the equivalent but on the leading edge.
4713    pub suffix_text: Option<String>,
4714
4715    /// The style to use for the `suffix_text`.
4716    ///
4717    /// If `suffix_style` is a `WidgetStateTextStyle`, then the effective text
4718    /// style can depend on the `WidgetState::Focused` state, i.e. if the
4719    /// `TextField` is focused or not.
4720    ///
4721    /// If null, defaults to the `hint_style`.
4722    ///
4723    /// See also:
4724    ///
4725    ///  * `prefix_style`, the equivalent but on the leading edge.
4726    pub suffix_style: Option<AnyTextStyle>,
4727
4728    /// Optional color of the `suffix_icon`.
4729    ///
4730    /// Defaults to `icon_color`
4731    ///
4732    /// If `suffix_icon_color` is a `WidgetStateColor`, then the effective
4733    /// color can depend on the `WidgetState::Focused` state, i.e.
4734    /// if the `TextField` is focused or not.
4735    pub suffix_icon_color: Option<AnyColor>,
4736
4737    /// The constraints for the suffix icon.
4738    ///
4739    /// This can be used to modify the `BoxConstraints` surrounding `suffix_icon`.
4740    ///
4741    /// This property is particularly useful for getting the decoration's height
4742    /// less than the minimum tappable height (which is 48px when the visual
4743    /// density is set to `VisualDensity::standard`). This can be achieved by
4744    /// setting `is_dense` to true and setting the constraints' minimum height
4745    /// and width to a value lower than the minimum tappable size.
4746    ///
4747    /// If null, a `BoxConstraints` with a minimum width and height of 48px is
4748    /// used.
4749    pub suffix_icon_constraints: Option<BoxConstraints>,
4750
4751    /// Optional text to place below the line as a character count.
4752    ///
4753    /// Rendered using `counter_style`. Uses `helper_style` if `counter_style` is
4754    /// null.
4755    ///
4756    /// The semantic label can be replaced by providing a `semantic_counter_text`.
4757    ///
4758    /// If null or an empty string and `counter` isn't specified, then nothing
4759    /// will appear in the counter's location.
4760    pub counter_text: Option<String>,
4761
4762    /// Optional custom counter widget to go in the place otherwise occupied by
4763    /// `counter_text`. If this property is non null, then `counter_text` is
4764    /// ignored.
4765    pub counter: Option<WidgetRef>,
4766
4767    /// The style to use for the `counter_text`.
4768    ///
4769    /// If `counter_style` is a `WidgetStateTextStyle`, then the effective
4770    /// text style can depend on the `WidgetState::Focused` state, i.e.
4771    /// if the `TextField` is focused or not.
4772    ///
4773    /// If null, defaults to the `helper_style`.
4774    pub counter_style: Option<AnyTextStyle>,
4775
4776    /// If true the decoration's container is filled with `fill_color`.
4777    ///
4778    /// When `InputDecorator::is_hovering` is true, the `hover_color` is also blended
4779    /// into the final fill color.
4780    ///
4781    /// Typically this field set to true if `border` is an `UnderlineInputBorder`.
4782    ///
4783    /// The decoration's container is the area which is filled if `filled` is true
4784    /// and bordered per the `border`. It's the area adjacent to `icon` and above
4785    /// the widgets that contain `helper_text`, `error_text`, and `counter_text`.
4786    ///
4787    /// This property is false by default.
4788    pub filled: Option<bool>,
4789
4790    /// The base fill color of the decoration's container color.
4791    ///
4792    /// When `InputDecorator::is_hovering` is true, the `hover_color` is also blended
4793    /// into the final fill color.
4794    ///
4795    /// By default the `fill_color` is based on the current
4796    /// `InputDecorationThemeData::fill_color`.
4797    ///
4798    /// The decoration's container is the area which is filled if `filled` is true
4799    /// and bordered per the `border`. It's the area adjacent to `icon` and above
4800    /// the widgets that contain `helper_text`, `error_text`, and `counter_text`.
4801    pub fill_color: Option<AnyColor>,
4802
4803    /// The fill color of the decoration's container when it has the input focus.
4804    ///
4805    /// By default the `focus_color` is based on the current
4806    /// `InputDecorationThemeData::focus_color`.
4807    ///
4808    /// This `focus_color` is ignored by `TextField` and `TextFormField` because
4809    /// they don't respond to focus changes by changing their decorator's
4810    /// container color, they respond by changing their border to the
4811    /// `focused_border`, which you can change the color of.
4812    ///
4813    /// The decoration's container is the area which is filled if `filled` is true
4814    /// and bordered per the `border`. It's the area adjacent to `icon` and above
4815    /// the widgets that contain `helper_text`, `error_text`, and `counter_text`.
4816    pub focus_color: Option<Color>,
4817
4818    /// The color of the highlight for the decoration shown if the container
4819    /// is being hovered over by a mouse.
4820    ///
4821    /// If `filled` is true, the `hover_color` is blended with `fill_color` and
4822    /// fills the decoration's container.
4823    ///
4824    /// If `filled` is false, and `InputDecorator::is_focused` is false, the color
4825    /// is blended over the `enabled_border`'s color.
4826    ///
4827    /// By default the `hover_color` is based on the current `Theme`.
4828    ///
4829    /// The decoration's container is the area which is filled if `filled` is true
4830    /// and bordered per the `border`. It's the area adjacent to `icon` and above
4831    /// the widgets that contain `helper_text`, `error_text`, and `counter_text`.
4832    pub hover_color: Option<Color>,
4833
4834    /// The border to display when the `InputDecorator` does not have the focus and
4835    /// is showing an error.
4836    ///
4837    /// See also:
4838    ///
4839    ///  * `InputDecorator::is_focused`, which is true if the `InputDecorator`'s child
4840    ///    has the focus.
4841    ///  * `InputDecoration::error_text`, the error shown by the `InputDecorator`, if non-null.
4842    ///  * `border`, for a description of where the `InputDecorator` border appears.
4843    ///  * `UnderlineInputBorder`, an `InputDecorator` border which draws a horizontal
4844    ///    line at the bottom of the input decorator's container.
4845    ///  * `OutlineInputBorder`, an `InputDecorator` border which draws a
4846    ///    rounded rectangle around the input decorator's container.
4847    ///  * `InputBorderRef::none()`, which doesn't draw a border.
4848    ///  * `focused_border`, displayed when `InputDecorator::is_focused` is true
4849    ///    and `InputDecoration::error_text` is null.
4850    ///  * `focused_error_border`, displayed when `InputDecorator::is_focused` is true
4851    ///    and `InputDecoration::error_text` is non-null.
4852    ///  * `disabled_border`, displayed when `InputDecoration::enabled` is false
4853    ///    and `InputDecoration::error_text` is null.
4854    ///  * `enabled_border`, displayed when `InputDecoration::enabled` is true
4855    ///    and `InputDecoration::error_text` is null.
4856    pub error_border: Option<InputBorderRef>,
4857
4858    /// The border to display when the `InputDecorator` has the focus and is not
4859    /// showing an error.
4860    ///
4861    /// See also:
4862    ///
4863    ///  * `InputDecorator::is_focused`, which is true if the `InputDecorator`'s child
4864    ///    has the focus.
4865    ///  * `InputDecoration::error_text`, the error shown by the `InputDecorator`, if non-null.
4866    ///  * `border`, for a description of where the `InputDecorator` border appears.
4867    ///  * `UnderlineInputBorder`, an `InputDecorator` border which draws a horizontal
4868    ///    line at the bottom of the input decorator's container.
4869    ///  * `OutlineInputBorder`, an `InputDecorator` border which draws a
4870    ///    rounded rectangle around the input decorator's container.
4871    ///  * `InputBorderRef::none()`, which doesn't draw a border.
4872    ///  * `error_border`, displayed when `InputDecorator::is_focused` is false
4873    ///    and `InputDecoration::error_text` is non-null.
4874    ///  * `focused_error_border`, displayed when `InputDecorator::is_focused` is true
4875    ///    and `InputDecoration::error_text` is non-null.
4876    ///  * `disabled_border`, displayed when `InputDecoration::enabled` is false
4877    ///    and `InputDecoration::error_text` is null.
4878    ///  * `enabled_border`, displayed when `InputDecoration::enabled` is true
4879    ///    and `InputDecoration::error_text` is null.
4880    pub focused_border: Option<InputBorderRef>,
4881
4882    /// The border to display when the `InputDecorator` has the focus and is
4883    /// showing an error.
4884    ///
4885    /// See also:
4886    ///
4887    ///  * `InputDecorator::is_focused`, which is true if the `InputDecorator`'s child
4888    ///    has the focus.
4889    ///  * `InputDecoration::error_text`, the error shown by the `InputDecorator`, if non-null.
4890    ///  * `border`, for a description of where the `InputDecorator` border appears.
4891    ///  * `UnderlineInputBorder`, an `InputDecorator` border which draws a horizontal
4892    ///    line at the bottom of the input decorator's container.
4893    ///  * `OutlineInputBorder`, an `InputDecorator` border which draws a
4894    ///    rounded rectangle around the input decorator's container.
4895    ///  * `InputBorderRef::none()`, which doesn't draw a border.
4896    ///  * `error_border`, displayed when `InputDecorator::is_focused` is false
4897    ///    and `InputDecoration::error_text` is non-null.
4898    ///  * `focused_border`, displayed when `InputDecorator::is_focused` is true
4899    ///    and `InputDecoration::error_text` is null.
4900    ///  * `disabled_border`, displayed when `InputDecoration::enabled` is false
4901    ///    and `InputDecoration::error_text` is null.
4902    ///  * `enabled_border`, displayed when `InputDecoration::enabled` is true
4903    ///    and `InputDecoration::error_text` is null.
4904    pub focused_error_border: Option<InputBorderRef>,
4905
4906    /// The border to display when the `InputDecorator` is disabled and is not
4907    /// showing an error.
4908    ///
4909    /// See also:
4910    ///
4911    ///  * `InputDecoration::enabled`, which is false if the `InputDecorator` is disabled.
4912    ///  * `InputDecoration::error_text`, the error shown by the `InputDecorator`, if non-null.
4913    ///  * `border`, for a description of where the `InputDecorator` border appears.
4914    ///  * `UnderlineInputBorder`, an `InputDecorator` border which draws a horizontal
4915    ///    line at the bottom of the input decorator's container.
4916    ///  * `OutlineInputBorder`, an `InputDecorator` border which draws a
4917    ///    rounded rectangle around the input decorator's container.
4918    ///  * `InputBorderRef::none()`, which doesn't draw a border.
4919    ///  * `error_border`, displayed when `InputDecorator::is_focused` is false
4920    ///    and `InputDecoration::error_text` is non-null.
4921    ///  * `focused_border`, displayed when `InputDecorator::is_focused` is true
4922    ///    and `InputDecoration::error_text` is null.
4923    ///  * `focused_error_border`, displayed when `InputDecorator::is_focused` is true
4924    ///    and `InputDecoration::error_text` is non-null.
4925    ///  * `enabled_border`, displayed when `InputDecoration::enabled` is true
4926    ///    and `InputDecoration::error_text` is null.
4927    pub disabled_border: Option<InputBorderRef>,
4928
4929    /// The border to display when the `InputDecorator` is enabled and is not
4930    /// showing an error.
4931    ///
4932    /// See also:
4933    ///
4934    ///  * `InputDecoration::enabled`, which is false if the `InputDecorator` is disabled.
4935    ///  * `InputDecoration::error_text`, the error shown by the `InputDecorator`, if non-null.
4936    ///  * `border`, for a description of where the `InputDecorator` border appears.
4937    ///  * `UnderlineInputBorder`, an `InputDecorator` border which draws a horizontal
4938    ///    line at the bottom of the input decorator's container.
4939    ///  * `OutlineInputBorder`, an `InputDecorator` border which draws a
4940    ///    rounded rectangle around the input decorator's container.
4941    ///  * `InputBorderRef::none()`, which doesn't draw a border.
4942    ///  * `error_border`, displayed when `InputDecorator::is_focused` is false
4943    ///    and `InputDecoration::error_text` is non-null.
4944    ///  * `focused_border`, displayed when `InputDecorator::is_focused` is true
4945    ///    and `InputDecoration::error_text` is null.
4946    ///  * `focused_error_border`, displayed when `InputDecorator::is_focused` is true
4947    ///    and `InputDecoration::error_text` is non-null.
4948    ///  * `disabled_border`, displayed when `InputDecoration::enabled` is false
4949    ///    and `InputDecoration::error_text` is null.
4950    pub enabled_border: Option<InputBorderRef>,
4951
4952    /// The shape of the border to draw around the decoration's container.
4953    ///
4954    /// If `border` is a `WidgetStateInputBorder` then the effective border is resolved
4955    /// in the following states:
4956    ///  * `WidgetState::Disabled`.
4957    ///  * `WidgetState::Error`.
4958    ///  * `WidgetState::Focused`.
4959    ///  * `WidgetState::Hovered`.
4960    ///
4961    /// If `border` derives from `InputBorder` the border's `InputBorder::border_side`,
4962    /// i.e. the border's color and width, will be overridden to reflect the input
4963    /// decorator's state. Only the border's shape is used. If custom  `BorderSide`
4964    /// values are desired for a given state, all five borders – `error_border`,
4965    /// `focused_border`, `enabled_border`, `disabled_border`, `focused_error_border` – must be set.
4966    ///
4967    /// The decoration's container is the area which is filled if `filled` is
4968    /// true and bordered per the `border`. It's the area adjacent to
4969    /// `InputDecoration::icon` and above the widgets that contain
4970    /// `InputDecoration::helper_text`, `InputDecoration::error_text`, and
4971    /// `InputDecoration::counter_text`.
4972    ///
4973    /// The border's bounds, i.e. the value of `border.getOuterPath()`, define
4974    /// the area to be filled.
4975    ///
4976    /// This property is only used when the appropriate one of `error_border`,
4977    /// `focused_border`, `focused_error_border`, `disabled_border`, or `enabled_border`
4978    /// is not specified. This border's `InputBorder::border_side` property is
4979    /// configured by the InputDecorator, depending on the values of
4980    /// `InputDecoration::error_text`, `InputDecoration::enabled`,
4981    /// `InputDecorator::is_focused` and the current `Theme`.
4982    ///
4983    /// Typically one of `UnderlineInputBorder` or `OutlineInputBorder`.
4984    /// If null, InputDecorator's default is `const UnderlineInputBorder()`.
4985    ///
4986    /// See also:
4987    ///
4988    ///  * `InputBorderRef::none()`, which doesn't draw a border.
4989    ///  * `UnderlineInputBorder`, which draws a horizontal line at the
4990    ///    bottom of the input decorator's container.
4991    ///  * `OutlineInputBorder`, an `InputDecorator` border which draws a
4992    ///    rounded rectangle around the input decorator's container.
4993    pub border: Option<InputBorderRef>,
4994
4995    /// If false the opacity of the visual elements is reduced, including `helper_text`,`error_text`, and `counter_text`.
4996    ///
4997    /// This property is true by default.
4998    pub enabled: bool,
4999
5000    /// A semantic label for the `counter_text`.
5001    ///
5002    /// Defaults to null.
5003    ///
5004    /// If provided, this replaces the semantic label of the `counter_text`.
5005    pub semantic_counter_text: Option<String>,
5006
5007    /// Typically set to true when the `InputDecorator` contains a multiline
5008    /// `TextField` (`TextField::max_lines` is null or > 1) to override the default
5009    /// behavior of aligning the label with the center of the `TextField`.
5010    ///
5011    /// Defaults to false.
5012    pub align_label_with_hint: Option<bool>,
5013
5014    /// Defines minimum and maximum sizes for the `InputDecorator`.
5015    ///
5016    /// Typically the decorator will fill the horizontal space it is given. For
5017    /// larger screens, it may be useful to have the maximum width clamped to
5018    /// a given value so it doesn't fill the whole screen. This property
5019    /// allows you to control how big the decorator will be in its available
5020    /// space.
5021    ///
5022    /// If null, then the ambient `InputDecorationThemeData::constraints` will be used.
5023    /// If that is null then the decorator will fill the available width with
5024    /// a default height based on text size.
5025    pub constraints: Option<BoxConstraints>,
5026
5027    /// Defines how compact the decoration's layout will be.
5028    ///
5029    /// The vertical aspect of the default or user-specified `content_padding` is adjusted
5030    /// automatically based on `visual_density`.
5031    ///
5032    /// When the visual density is `VisualDensity::compact`, the vertical aspect of
5033    /// `content_padding` is reduced by 8 pixels.
5034    ///
5035    /// When the visual density is `VisualDensity::comfortable`, the vertical aspect of
5036    /// `content_padding` is reduced by 4 pixels.
5037    ///
5038    /// When the visual density is `VisualDensity::standard` vertical aspect of
5039    /// `content_padding` is not changed.
5040    ///
5041    /// If null, then the ambient `InputDecorationThemeData::visual_density` will be used.
5042    /// If that is null then `ThemeData::visual_density` will be used.
5043    ///
5044    /// See also:
5045    ///
5046    ///  * `ThemeData::visual_density`, which specifies the `visual_density` for all widgets
5047    ///    within a `Theme`.
5048    ///  * `InputDecorationThemeData::visual_density`, which can override this setting for a
5049    ///    given decorator.
5050    pub visual_density: Option<VisualDensity>,
5051
5052    /// The padding around the supporting text row, which contains the helper
5053    /// text, the error text, and the counter.
5054    ///
5055    /// The start and end values set the horizontal position of the row, the
5056    /// same way `InputDecoration::content_padding` does for the input. The top
5057    /// value is the gap between the bottom of the decoration's container and
5058    /// the row, and the bottom value is the space below the row.
5059    ///
5060    /// If null, the row uses these defaults:
5061    ///
5062    ///  * start and end: the start and end values of
5063    ///    `InputDecoration::content_padding`.
5064    ///  * top: 4.0 for Material 3, 8.0 for Material 2.
5065    ///  * bottom: 0.0.
5066    ///
5067    /// If non-null, every side of this value is used as is, including sides
5068    /// that are zero. For example, `EdgeInsetsDirectional.only(start: 24.0)`
5069    /// sets the top gap to zero, so the supporting text sits directly against
5070    /// the container. To change the horizontal padding while keeping the
5071    /// default Material 3 gap, set the top value explicitly:
5072    ///
5073    /// ```text
5074    /// const InputDecoration(
5075    ///   helperText: 'Helper text',
5076    ///   supportingTextPadding: EdgeInsetsDirectional.fromSTEB(24.0, 4.0, 24.0, 0.0),
5077    /// )
5078    /// ```
5079    ///
5080    /// If both this and `InputDecorationThemeData::supporting_text_padding` are
5081    /// non-null, this value replaces the theme value entirely. The two are not
5082    /// merged side by side.
5083    pub supporting_text_padding: Option<EdgeInsetsGeometry>,
5084}
5085
5086#[allow(deprecated)]
5087impl InputDecoration {
5088    /// Creates a bundle of the border, labels, icons, and styles used to
5089    /// decorate a Material Design text field.
5090    ///
5091    /// Unless specified by the ambient `InputDecorationThemeData`, `InputDecorator`
5092    /// defaults `is_dense` to false and `filled` to false. The default border is
5093    /// an instance of `UnderlineInputBorder`. If `border` is `InputBorderRef::none()`
5094    /// then no border is drawn.
5095    ///
5096    /// Only one of `prefix` and `prefix_text` can be specified.
5097    ///
5098    /// Similarly, only one of `suffix` and `suffix_text` can be specified.
5099    pub fn new() -> InputDecoration {
5100        InputDecoration {
5101            icon: None,
5102            icon_color: None,
5103            label: None,
5104            label_text: None,
5105            label_style: None,
5106            floating_label_style: None,
5107            label_text_direction: None,
5108            helper: None,
5109            helper_text: None,
5110            helper_style: None,
5111            helper_max_lines: None,
5112            hint_text: None,
5113            hint: None,
5114            hint_style: None,
5115            hint_text_direction: None,
5116            hint_max_lines: None,
5117            hint_fade_duration: None,
5118            maintain_hint_height: true,
5119            maintain_hint_size: true,
5120            maintain_label_size: false,
5121            error: None,
5122            error_text: None,
5123            error_style: None,
5124            error_max_lines: None,
5125            floating_label_behavior: None,
5126            floating_label_alignment: None,
5127            is_dense: None,
5128            content_padding: None,
5129            is_collapsed: None,
5130            prefix_icon: None,
5131            prefix_icon_constraints: None,
5132            prefix: None,
5133            prefix_text: None,
5134            prefix_style: None,
5135            prefix_icon_color: None,
5136            suffix_icon: None,
5137            suffix: None,
5138            suffix_text: None,
5139            suffix_style: None,
5140            suffix_icon_color: None,
5141            suffix_icon_constraints: None,
5142            counter_text: None,
5143            counter: None,
5144            counter_style: None,
5145            filled: None,
5146            fill_color: None,
5147            focus_color: None,
5148            hover_color: None,
5149            error_border: None,
5150            focused_border: None,
5151            focused_error_border: None,
5152            disabled_border: None,
5153            enabled_border: None,
5154            border: None,
5155            enabled: true,
5156            semantic_counter_text: None,
5157            align_label_with_hint: None,
5158            constraints: None,
5159            visual_density: None,
5160            supporting_text_padding: None,
5161        }
5162    }
5163
5164    /// Defines an `InputDecorator` that is the same size as the input field.
5165    ///
5166    /// This type of input decoration does not include a border by default.
5167    ///
5168    /// A collapsed decoration cannot have `label_text`, `error_text`, `counter`,
5169    /// `icon`, prefixes, and suffixes.
5170    ///
5171    /// Sets the `is_collapsed` property to true.
5172    /// Sets the `content_padding` property to `EdgeInsets::ZERO`.
5173    pub fn collapsed(hint_text: Option<String>) -> InputDecoration {
5174        InputDecoration {
5175            icon: None,
5176            icon_color: None,
5177            label: None,
5178            label_text: None,
5179            label_style: None,
5180            floating_label_style: None,
5181            label_text_direction: None,
5182            helper: None,
5183            helper_text: None,
5184            helper_style: None,
5185            helper_max_lines: None,
5186            hint_text,
5187            hint: None,
5188            hint_style: None,
5189            hint_text_direction: None,
5190            hint_max_lines: None,
5191            hint_fade_duration: None,
5192            maintain_hint_height: true,
5193            maintain_hint_size: true,
5194            maintain_label_size: false,
5195            error: None,
5196            error_text: None,
5197            error_style: None,
5198            error_max_lines: None,
5199            floating_label_behavior: None,
5200            floating_label_alignment: None,
5201            is_dense: Some(false),
5202            content_padding: Some(EdgeInsets::ZERO.into()),
5203            is_collapsed: Some(true),
5204            prefix_icon: None,
5205            prefix_icon_constraints: None,
5206            prefix: None,
5207            prefix_text: None,
5208            prefix_style: None,
5209            prefix_icon_color: None,
5210            suffix_icon: None,
5211            suffix: None,
5212            suffix_text: None,
5213            suffix_style: None,
5214            suffix_icon_color: None,
5215            suffix_icon_constraints: None,
5216            counter_text: None,
5217            counter: None,
5218            counter_style: None,
5219            filled: Some(false),
5220            fill_color: None,
5221            focus_color: None,
5222            hover_color: None,
5223            error_border: None,
5224            focused_border: None,
5225            focused_error_border: None,
5226            disabled_border: None,
5227            enabled_border: None,
5228            border: Some(InputBorderRef::none()),
5229            enabled: true,
5230            semantic_counter_text: None,
5231            align_label_with_hint: Some(false),
5232            constraints: None,
5233            visual_density: None,
5234            supporting_text_padding: None,
5235        }
5236    }
5237
5238    /// Dart `InputDecoration(icon:)`.
5239    #[cfg_attr(debug_assertions, track_caller)]
5240    pub fn icon<K>(mut self, icon: impl IntoWidget<K>) -> InputDecoration {
5241        self.icon = Some(icon.into_widget());
5242        self
5243    }
5244
5245    /// Dart `InputDecoration(iconColor:)`.
5246    pub fn icon_color(mut self, icon_color: impl Into<AnyColor>) -> InputDecoration {
5247        self.icon_color = Some(icon_color.into());
5248        self
5249    }
5250
5251    /// Dart `InputDecoration(label:)`.
5252    #[cfg_attr(debug_assertions, track_caller)]
5253    pub fn label<K>(mut self, label: impl IntoWidget<K>) -> InputDecoration {
5254        self.label = Some(label.into_widget());
5255        self
5256    }
5257
5258    /// Dart `InputDecoration(labelText:)`.
5259    pub fn label_text(mut self, label_text: impl Into<String>) -> InputDecoration {
5260        self.label_text = Some(label_text.into());
5261        self
5262    }
5263
5264    /// Dart `InputDecoration(labelStyle:)`.
5265    pub fn label_style(mut self, label_style: impl Into<AnyTextStyle>) -> InputDecoration {
5266        self.label_style = Some(label_style.into());
5267        self
5268    }
5269
5270    /// Dart `InputDecoration(floatingLabelStyle:)`.
5271    pub fn floating_label_style(
5272        mut self,
5273        floating_label_style: impl Into<AnyTextStyle>,
5274    ) -> InputDecoration {
5275        self.floating_label_style = Some(floating_label_style.into());
5276        self
5277    }
5278
5279    /// Dart `InputDecoration(labelTextDirection:)`.
5280    pub fn label_text_direction(mut self, label_text_direction: TextDirection) -> InputDecoration {
5281        self.label_text_direction = Some(label_text_direction);
5282        self
5283    }
5284
5285    /// Dart `InputDecoration(helper:)`.
5286    #[cfg_attr(debug_assertions, track_caller)]
5287    pub fn helper<K>(mut self, helper: impl IntoWidget<K>) -> InputDecoration {
5288        self.helper = Some(helper.into_widget());
5289        self
5290    }
5291
5292    /// Dart `InputDecoration(helperText:)`.
5293    pub fn helper_text(mut self, helper_text: impl Into<String>) -> InputDecoration {
5294        self.helper_text = Some(helper_text.into());
5295        self
5296    }
5297
5298    /// Dart `InputDecoration(helperStyle:)`.
5299    pub fn helper_style(mut self, helper_style: impl Into<AnyTextStyle>) -> InputDecoration {
5300        self.helper_style = Some(helper_style.into());
5301        self
5302    }
5303
5304    /// Dart `InputDecoration(helperMaxLines:)`.
5305    pub fn helper_max_lines(mut self, helper_max_lines: i32) -> InputDecoration {
5306        self.helper_max_lines = Some(helper_max_lines);
5307        self
5308    }
5309
5310    /// Dart `InputDecoration(hintText:)`.
5311    pub fn hint_text(mut self, hint_text: impl Into<String>) -> InputDecoration {
5312        self.hint_text = Some(hint_text.into());
5313        self
5314    }
5315
5316    /// Dart `InputDecoration(hint:)`.
5317    #[cfg_attr(debug_assertions, track_caller)]
5318    pub fn hint<K>(mut self, hint: impl IntoWidget<K>) -> InputDecoration {
5319        self.hint = Some(hint.into_widget());
5320        self
5321    }
5322
5323    /// Dart `InputDecoration(hintStyle:)`.
5324    pub fn hint_style(mut self, hint_style: impl Into<AnyTextStyle>) -> InputDecoration {
5325        self.hint_style = Some(hint_style.into());
5326        self
5327    }
5328
5329    /// Dart `InputDecoration(hintTextDirection:)`.
5330    pub fn hint_text_direction(mut self, hint_text_direction: TextDirection) -> InputDecoration {
5331        self.hint_text_direction = Some(hint_text_direction);
5332        self
5333    }
5334
5335    /// Dart `InputDecoration(hintMaxLines:)`.
5336    pub fn hint_max_lines(mut self, hint_max_lines: i32) -> InputDecoration {
5337        self.hint_max_lines = Some(hint_max_lines);
5338        self
5339    }
5340
5341    /// Dart `InputDecoration(hintFadeDuration:)`.
5342    pub fn hint_fade_duration(mut self, hint_fade_duration: Duration) -> InputDecoration {
5343        self.hint_fade_duration = Some(hint_fade_duration);
5344        self
5345    }
5346
5347    /// Dart `InputDecoration(maintainHintHeight:)`.
5348    #[deprecated(
5349        note = "Use maintainHintSize instead. This will maintain both hint height and hint width. This feature was deprecated after v3.28.0-2.0.pre."
5350    )]
5351    pub fn maintain_hint_height(mut self, maintain_hint_height: bool) -> InputDecoration {
5352        self.maintain_hint_height = maintain_hint_height;
5353        self
5354    }
5355
5356    /// Dart `InputDecoration(maintainHintSize:)`.
5357    pub fn maintain_hint_size(mut self, maintain_hint_size: bool) -> InputDecoration {
5358        self.maintain_hint_size = maintain_hint_size;
5359        self
5360    }
5361
5362    /// Dart `InputDecoration(maintainLabelSize:)`.
5363    pub fn maintain_label_size(mut self, maintain_label_size: bool) -> InputDecoration {
5364        self.maintain_label_size = maintain_label_size;
5365        self
5366    }
5367
5368    /// Dart `InputDecoration(error:)`.
5369    #[cfg_attr(debug_assertions, track_caller)]
5370    pub fn error<K>(mut self, error: impl IntoWidget<K>) -> InputDecoration {
5371        self.error = Some(error.into_widget());
5372        self
5373    }
5374
5375    /// Dart `InputDecoration(errorText:)`.
5376    pub fn error_text(mut self, error_text: impl Into<String>) -> InputDecoration {
5377        self.error_text = Some(error_text.into());
5378        self
5379    }
5380
5381    /// Dart `InputDecoration(errorStyle:)`.
5382    pub fn error_style(mut self, error_style: impl Into<AnyTextStyle>) -> InputDecoration {
5383        self.error_style = Some(error_style.into());
5384        self
5385    }
5386
5387    /// Dart `InputDecoration(errorMaxLines:)`.
5388    pub fn error_max_lines(mut self, error_max_lines: i32) -> InputDecoration {
5389        self.error_max_lines = Some(error_max_lines);
5390        self
5391    }
5392
5393    /// Dart `InputDecoration(floatingLabelBehavior:)`.
5394    pub fn floating_label_behavior(
5395        mut self,
5396        floating_label_behavior: FloatingLabelBehavior,
5397    ) -> InputDecoration {
5398        self.floating_label_behavior = Some(floating_label_behavior);
5399        self
5400    }
5401
5402    /// Dart `InputDecoration(floatingLabelAlignment:)`.
5403    pub fn floating_label_alignment(
5404        mut self,
5405        floating_label_alignment: FloatingLabelAlignment,
5406    ) -> InputDecoration {
5407        self.floating_label_alignment = Some(floating_label_alignment);
5408        self
5409    }
5410
5411    /// Dart `InputDecoration(isCollapsed:)`.
5412    pub fn is_collapsed(mut self, is_collapsed: bool) -> InputDecoration {
5413        self.is_collapsed = Some(is_collapsed);
5414        self
5415    }
5416
5417    /// Dart `InputDecoration(isDense:)`.
5418    pub fn is_dense(mut self, is_dense: bool) -> InputDecoration {
5419        self.is_dense = Some(is_dense);
5420        self
5421    }
5422
5423    /// Dart `InputDecoration(contentPadding:)`.
5424    pub fn content_padding(
5425        mut self,
5426        content_padding: impl Into<EdgeInsetsGeometry>,
5427    ) -> InputDecoration {
5428        let content_padding = content_padding.into();
5429        self.content_padding = Some(content_padding);
5430        self
5431    }
5432
5433    /// Dart `InputDecoration(prefixIcon:)`.
5434    #[cfg_attr(debug_assertions, track_caller)]
5435    pub fn prefix_icon<K>(mut self, prefix_icon: impl IntoWidget<K>) -> InputDecoration {
5436        self.prefix_icon = Some(prefix_icon.into_widget());
5437        self
5438    }
5439
5440    /// Dart `InputDecoration(prefixIconConstraints:)`.
5441    pub fn prefix_icon_constraints(
5442        mut self,
5443        prefix_icon_constraints: BoxConstraints,
5444    ) -> InputDecoration {
5445        self.prefix_icon_constraints = Some(prefix_icon_constraints);
5446        self
5447    }
5448
5449    /// Dart `InputDecoration(prefix:)`.
5450    #[cfg_attr(debug_assertions, track_caller)]
5451    pub fn prefix<K>(mut self, prefix: impl IntoWidget<K>) -> InputDecoration {
5452        self.prefix = Some(prefix.into_widget());
5453        self
5454    }
5455
5456    /// Dart `InputDecoration(prefixText:)`.
5457    pub fn prefix_text(mut self, prefix_text: impl Into<String>) -> InputDecoration {
5458        self.prefix_text = Some(prefix_text.into());
5459        self
5460    }
5461
5462    /// Dart `InputDecoration(prefixStyle:)`.
5463    pub fn prefix_style(mut self, prefix_style: impl Into<AnyTextStyle>) -> InputDecoration {
5464        self.prefix_style = Some(prefix_style.into());
5465        self
5466    }
5467
5468    /// Dart `InputDecoration(prefixIconColor:)`.
5469    pub fn prefix_icon_color(mut self, prefix_icon_color: impl Into<AnyColor>) -> InputDecoration {
5470        self.prefix_icon_color = Some(prefix_icon_color.into());
5471        self
5472    }
5473
5474    /// Dart `InputDecoration(suffixIcon:)`.
5475    #[cfg_attr(debug_assertions, track_caller)]
5476    pub fn suffix_icon<K>(mut self, suffix_icon: impl IntoWidget<K>) -> InputDecoration {
5477        self.suffix_icon = Some(suffix_icon.into_widget());
5478        self
5479    }
5480
5481    /// Dart `InputDecoration(suffix:)`.
5482    #[cfg_attr(debug_assertions, track_caller)]
5483    pub fn suffix<K>(mut self, suffix: impl IntoWidget<K>) -> InputDecoration {
5484        self.suffix = Some(suffix.into_widget());
5485        self
5486    }
5487
5488    /// Dart `InputDecoration(suffixText:)`.
5489    pub fn suffix_text(mut self, suffix_text: impl Into<String>) -> InputDecoration {
5490        self.suffix_text = Some(suffix_text.into());
5491        self
5492    }
5493
5494    /// Dart `InputDecoration(suffixStyle:)`.
5495    pub fn suffix_style(mut self, suffix_style: impl Into<AnyTextStyle>) -> InputDecoration {
5496        self.suffix_style = Some(suffix_style.into());
5497        self
5498    }
5499
5500    /// Dart `InputDecoration(suffixIconColor:)`.
5501    pub fn suffix_icon_color(mut self, suffix_icon_color: impl Into<AnyColor>) -> InputDecoration {
5502        self.suffix_icon_color = Some(suffix_icon_color.into());
5503        self
5504    }
5505
5506    /// Dart `InputDecoration(suffixIconConstraints:)`.
5507    pub fn suffix_icon_constraints(
5508        mut self,
5509        suffix_icon_constraints: BoxConstraints,
5510    ) -> InputDecoration {
5511        self.suffix_icon_constraints = Some(suffix_icon_constraints);
5512        self
5513    }
5514
5515    /// Dart `InputDecoration(counter:)`.
5516    #[cfg_attr(debug_assertions, track_caller)]
5517    pub fn counter<K>(mut self, counter: impl IntoWidget<K>) -> InputDecoration {
5518        self.counter = Some(counter.into_widget());
5519        self
5520    }
5521
5522    /// Dart `InputDecoration(counterText:)`.
5523    pub fn counter_text(mut self, counter_text: impl Into<String>) -> InputDecoration {
5524        self.counter_text = Some(counter_text.into());
5525        self
5526    }
5527
5528    /// Dart `InputDecoration(counterStyle:)`.
5529    pub fn counter_style(mut self, counter_style: impl Into<AnyTextStyle>) -> InputDecoration {
5530        self.counter_style = Some(counter_style.into());
5531        self
5532    }
5533
5534    /// Dart `InputDecoration(filled:)`.
5535    pub fn filled(mut self, filled: bool) -> InputDecoration {
5536        self.filled = Some(filled);
5537        self
5538    }
5539
5540    /// Dart `InputDecoration(fillColor:)`.
5541    pub fn fill_color(mut self, fill_color: impl Into<AnyColor>) -> InputDecoration {
5542        self.fill_color = Some(fill_color.into());
5543        self
5544    }
5545
5546    /// Dart `InputDecoration(focusColor:)`.
5547    pub fn focus_color(mut self, focus_color: Color) -> InputDecoration {
5548        self.focus_color = Some(focus_color);
5549        self
5550    }
5551
5552    /// Dart `InputDecoration(hoverColor:)`.
5553    pub fn hover_color(mut self, hover_color: Color) -> InputDecoration {
5554        self.hover_color = Some(hover_color);
5555        self
5556    }
5557
5558    /// Dart `InputDecoration(errorBorder:)`.
5559    pub fn error_border(mut self, error_border: impl Into<InputBorderRef>) -> InputDecoration {
5560        self.error_border = Some(error_border.into());
5561        self
5562    }
5563
5564    /// Dart `InputDecoration(focusedBorder:)`.
5565    pub fn focused_border(mut self, focused_border: impl Into<InputBorderRef>) -> InputDecoration {
5566        self.focused_border = Some(focused_border.into());
5567        self
5568    }
5569
5570    /// Dart `InputDecoration(focusedErrorBorder:)`.
5571    pub fn focused_error_border(
5572        mut self,
5573        focused_error_border: impl Into<InputBorderRef>,
5574    ) -> InputDecoration {
5575        self.focused_error_border = Some(focused_error_border.into());
5576        self
5577    }
5578
5579    /// Dart `InputDecoration(disabledBorder:)`.
5580    pub fn disabled_border(
5581        mut self,
5582        disabled_border: impl Into<InputBorderRef>,
5583    ) -> InputDecoration {
5584        self.disabled_border = Some(disabled_border.into());
5585        self
5586    }
5587
5588    /// Dart `InputDecoration(enabledBorder:)`.
5589    pub fn enabled_border(mut self, enabled_border: impl Into<InputBorderRef>) -> InputDecoration {
5590        self.enabled_border = Some(enabled_border.into());
5591        self
5592    }
5593
5594    /// Dart `InputDecoration(border:)`.
5595    pub fn border(mut self, border: impl Into<InputBorderRef>) -> InputDecoration {
5596        self.border = Some(border.into());
5597        self
5598    }
5599
5600    /// Dart `InputDecoration(enabled:)`.
5601    pub fn enabled(mut self, enabled: bool) -> InputDecoration {
5602        self.enabled = enabled;
5603        self
5604    }
5605
5606    /// Dart `InputDecoration(semanticCounterText:)`.
5607    pub fn semantic_counter_text(
5608        mut self,
5609        semantic_counter_text: impl Into<String>,
5610    ) -> InputDecoration {
5611        self.semantic_counter_text = Some(semantic_counter_text.into());
5612        self
5613    }
5614
5615    /// Dart `InputDecoration(alignLabelWithHint:)`.
5616    pub fn align_label_with_hint(mut self, align_label_with_hint: bool) -> InputDecoration {
5617        self.align_label_with_hint = Some(align_label_with_hint);
5618        self
5619    }
5620
5621    /// Dart `InputDecoration(constraints:)`.
5622    pub fn constraints(mut self, constraints: BoxConstraints) -> InputDecoration {
5623        self.constraints = Some(constraints);
5624        self
5625    }
5626
5627    /// Dart `InputDecoration(visualDensity:)`.
5628    pub fn visual_density(mut self, visual_density: VisualDensity) -> InputDecoration {
5629        self.visual_density = Some(visual_density);
5630        self
5631    }
5632
5633    /// Dart `InputDecoration(supportingTextPadding:)`.
5634    pub fn supporting_text_padding(
5635        mut self,
5636        supporting_text_padding: impl Into<EdgeInsetsGeometry>,
5637    ) -> InputDecoration {
5638        let supporting_text_padding = supporting_text_padding.into();
5639        self.supporting_text_padding = Some(supporting_text_padding);
5640        self
5641    }
5642
5643    /// Dart's constructor asserts on pairs of arguments, which a fluent chain only completes
5644    /// once it is handed over: `InputDecorator` calls this when it is turned into a
5645    /// `WidgetRef` (`into_widget`).
5646    pub(crate) fn debug_check_arguments(&self) {
5647        debug_assert!(
5648            !(self.label.is_some() && self.label_text.is_some()),
5649            "Declaring both label and labelText is not supported."
5650        );
5651        debug_assert!(
5652            self.hint.is_none() || self.hint_text.is_none(),
5653            "Declaring both hint and hintText is not supported."
5654        );
5655        debug_assert!(
5656            !(self.helper.is_some() && self.helper_text.is_some()),
5657            "Declaring both helper and helperText is not supported."
5658        );
5659        debug_assert!(
5660            !(self.prefix.is_some() && self.prefix_text.is_some()),
5661            "Declaring both prefix and prefixText is not supported."
5662        );
5663        debug_assert!(
5664            !(self.suffix.is_some() && self.suffix_text.is_some()),
5665            "Declaring both suffix and suffixText is not supported."
5666        );
5667        debug_assert!(
5668            !(self.error.is_some() && self.error_text.is_some()),
5669            "Declaring both error and errorText is not supported."
5670        );
5671    }
5672
5673    /// Creates a copy of this input decoration with the given fields replaced
5674    /// by the new values.
5675    ///
5676    /// Dart's named arguments are the fluent setters on the copy
5677    /// (`decoration.copy_with().label_text("Name")`).
5678    pub fn copy_with(&self) -> InputDecoration {
5679        self.clone()
5680    }
5681
5682    /// Used by widgets like `TextField` and `InputDecorator` to create a new
5683    /// `InputDecoration` with default values taken from the `input_decoration_theme`.
5684    ///
5685    /// Only null valued properties from this `InputDecoration` are replaced
5686    /// by the corresponding values from `input_decoration_theme`.
5687    ///
5688    /// Dart's parameter is an `Object` that must be an `InputDecorationTheme` or an
5689    /// `InputDecorationThemeData`; here either converts into the data.
5690    pub fn apply_defaults(
5691        &self,
5692        input_decoration_theme: impl Into<InputDecorationThemeData>,
5693    ) -> InputDecoration {
5694        let theme: InputDecorationThemeData = input_decoration_theme.into();
5695        let mut decoration = self.copy_with();
5696        decoration.label_style = self
5697            .label_style
5698            .clone()
5699            .or_else(|| theme.label_style.clone());
5700        decoration.floating_label_style = self
5701            .floating_label_style
5702            .clone()
5703            .or_else(|| theme.floating_label_style.clone());
5704        decoration.helper_style = self
5705            .helper_style
5706            .clone()
5707            .or_else(|| theme.helper_style.clone());
5708        decoration.helper_max_lines = self.helper_max_lines.or(theme.helper_max_lines);
5709        decoration.hint_style = self.hint_style.clone().or_else(|| theme.hint_style.clone());
5710        decoration.hint_fade_duration = self.hint_fade_duration.or(theme.hint_fade_duration);
5711        decoration.hint_max_lines = self.hint_max_lines.or(theme.hint_max_lines);
5712        decoration.error_style = self
5713            .error_style
5714            .clone()
5715            .or_else(|| theme.error_style.clone());
5716        decoration.error_max_lines = self.error_max_lines.or(theme.error_max_lines);
5717        decoration.floating_label_behavior = self
5718            .floating_label_behavior
5719            .or(Some(theme.floating_label_behavior));
5720        decoration.floating_label_alignment = self
5721            .floating_label_alignment
5722            .or(Some(theme.floating_label_alignment));
5723        decoration.is_dense = self.is_dense.or(Some(theme.is_dense));
5724        decoration.content_padding = self.content_padding.or(theme.content_padding);
5725        decoration.is_collapsed = self.is_collapsed.or(Some(theme.is_collapsed));
5726        decoration.icon_color = self.icon_color.clone().or_else(|| theme.icon_color.clone());
5727        decoration.prefix_style = self
5728            .prefix_style
5729            .clone()
5730            .or_else(|| theme.prefix_style.clone());
5731        decoration.prefix_icon_color = self
5732            .prefix_icon_color
5733            .clone()
5734            .or_else(|| theme.prefix_icon_color.clone());
5735        decoration.prefix_icon_constraints = self
5736            .prefix_icon_constraints
5737            .or(theme.prefix_icon_constraints);
5738        decoration.suffix_style = self
5739            .suffix_style
5740            .clone()
5741            .or_else(|| theme.suffix_style.clone());
5742        decoration.suffix_icon_color = self
5743            .suffix_icon_color
5744            .clone()
5745            .or_else(|| theme.suffix_icon_color.clone());
5746        decoration.suffix_icon_constraints = self
5747            .suffix_icon_constraints
5748            .or(theme.suffix_icon_constraints);
5749        decoration.counter_style = self
5750            .counter_style
5751            .clone()
5752            .or_else(|| theme.counter_style.clone());
5753        decoration.filled = self.filled.or(Some(theme.filled));
5754        decoration.fill_color = self.fill_color.clone().or_else(|| theme.fill_color.clone());
5755        decoration.focus_color = self.focus_color.or(theme.focus_color);
5756        decoration.hover_color = self.hover_color.or(theme.hover_color);
5757        decoration.error_border = self
5758            .error_border
5759            .clone()
5760            .or_else(|| theme.error_border.clone());
5761        decoration.focused_border = self
5762            .focused_border
5763            .clone()
5764            .or_else(|| theme.focused_border.clone());
5765        decoration.focused_error_border = self
5766            .focused_error_border
5767            .clone()
5768            .or_else(|| theme.focused_error_border.clone());
5769        decoration.disabled_border = self
5770            .disabled_border
5771            .clone()
5772            .or_else(|| theme.disabled_border.clone());
5773        decoration.enabled_border = self
5774            .enabled_border
5775            .clone()
5776            .or_else(|| theme.enabled_border.clone());
5777        decoration.border = self.border.clone().or_else(|| theme.border.clone());
5778        decoration.align_label_with_hint = self
5779            .align_label_with_hint
5780            .or(Some(theme.align_label_with_hint));
5781        decoration.constraints = self.constraints.or(theme.constraints);
5782        decoration.visual_density = self.visual_density.or(theme.visual_density);
5783        decoration.supporting_text_padding = self
5784            .supporting_text_padding
5785            .or(theme.supporting_text_padding);
5786        decoration
5787    }
5788}
5789
5790impl Default for InputDecoration {
5791    fn default() -> InputDecoration {
5792        InputDecoration::new()
5793    }
5794}
5795
5796#[allow(deprecated)]
5797impl PartialEq for InputDecoration {
5798    // Dart compares the widgets by their `==`, which is identity.
5799    fn eq(&self, other: &InputDecoration) -> bool {
5800        same_widget(&other.icon, &self.icon)
5801            && other.icon_color == self.icon_color
5802            && same_widget(&other.label, &self.label)
5803            && other.label_text == self.label_text
5804            && other.label_style == self.label_style
5805            && other.floating_label_style == self.floating_label_style
5806            && other.label_text_direction == self.label_text_direction
5807            && same_widget(&other.helper, &self.helper)
5808            && other.helper_text == self.helper_text
5809            && other.helper_style == self.helper_style
5810            && other.helper_max_lines == self.helper_max_lines
5811            && other.hint_text == self.hint_text
5812            && same_widget(&other.hint, &self.hint)
5813            && other.hint_style == self.hint_style
5814            && other.hint_text_direction == self.hint_text_direction
5815            && other.hint_max_lines == self.hint_max_lines
5816            && other.hint_fade_duration == self.hint_fade_duration
5817            && other.maintain_hint_height == self.maintain_hint_height
5818            && other.maintain_hint_size == self.maintain_hint_size
5819            && other.maintain_label_size == self.maintain_label_size
5820            && same_widget(&other.error, &self.error)
5821            && other.error_text == self.error_text
5822            && other.error_style == self.error_style
5823            && other.error_max_lines == self.error_max_lines
5824            && other.floating_label_behavior == self.floating_label_behavior
5825            && other.floating_label_alignment == self.floating_label_alignment
5826            && other.is_dense == self.is_dense
5827            && other.content_padding == self.content_padding
5828            && other.is_collapsed == self.is_collapsed
5829            && same_widget(&other.prefix_icon, &self.prefix_icon)
5830            && other.prefix_icon_color == self.prefix_icon_color
5831            && same_widget(&other.prefix, &self.prefix)
5832            && other.prefix_text == self.prefix_text
5833            && other.prefix_style == self.prefix_style
5834            && other.prefix_icon_constraints == self.prefix_icon_constraints
5835            && same_widget(&other.suffix_icon, &self.suffix_icon)
5836            && other.suffix_icon_color == self.suffix_icon_color
5837            && same_widget(&other.suffix, &self.suffix)
5838            && other.suffix_text == self.suffix_text
5839            && other.suffix_style == self.suffix_style
5840            && other.suffix_icon_constraints == self.suffix_icon_constraints
5841            && same_widget(&other.counter, &self.counter)
5842            && other.counter_text == self.counter_text
5843            && other.counter_style == self.counter_style
5844            && other.filled == self.filled
5845            && other.fill_color == self.fill_color
5846            && other.focus_color == self.focus_color
5847            && other.hover_color == self.hover_color
5848            && other.error_border == self.error_border
5849            && other.focused_border == self.focused_border
5850            && other.focused_error_border == self.focused_error_border
5851            && other.disabled_border == self.disabled_border
5852            && other.enabled_border == self.enabled_border
5853            && other.border == self.border
5854            && other.enabled == self.enabled
5855            && other.semantic_counter_text == self.semantic_counter_text
5856            && other.align_label_with_hint == self.align_label_with_hint
5857            && other.constraints == self.constraints
5858            && other.visual_density == self.visual_density
5859            && other.supporting_text_padding == self.supporting_text_padding
5860    }
5861}
5862
5863/// Dart's `toString`.
5864#[allow(deprecated)]
5865impl Debug for InputDecoration {
5866    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5867        let mut description: Vec<String> = Vec::new();
5868        if let Some(icon) = &self.icon {
5869            description.push(format!("icon: {:?}", icon));
5870        }
5871        if let Some(icon_color) = &self.icon_color {
5872            description.push(format!("iconColor: {:?}", icon_color));
5873        }
5874        if let Some(label) = &self.label {
5875            description.push(format!("label: {:?}", label));
5876        }
5877        if let Some(label_text) = &self.label_text {
5878            description.push(format!("labelText: \"{}\"", label_text));
5879        }
5880        if let Some(floating_label_style) = &self.floating_label_style {
5881            description.push(format!(
5882                "floatingLabelStyle: \"{:?}\"",
5883                floating_label_style
5884            ));
5885        }
5886        if let Some(helper) = &self.helper {
5887            description.push(format!("helper: \"{:?}\"", helper));
5888        }
5889        if let Some(helper_text) = &self.helper_text {
5890            description.push(format!("helperText: \"{}\"", helper_text));
5891        }
5892        if let Some(helper_max_lines) = &self.helper_max_lines {
5893            description.push(format!("helperMaxLines: \"{:?}\"", helper_max_lines));
5894        }
5895        if let Some(hint_text) = &self.hint_text {
5896            description.push(format!("hintText: \"{}\"", hint_text));
5897        }
5898        if let Some(hint) = &self.hint {
5899            description.push(format!("hint: {:?}", hint));
5900        }
5901        if let Some(hint_max_lines) = &self.hint_max_lines {
5902            description.push(format!("hintMaxLines: \"{:?}\"", hint_max_lines));
5903        }
5904        if let Some(hint_fade_duration) = &self.hint_fade_duration {
5905            description.push(format!("hintFadeDuration: \"{:?}\"", hint_fade_duration));
5906        }
5907        if !self.maintain_hint_height {
5908            description.push("maintainHintHeight: false".to_owned());
5909        }
5910        if !self.maintain_hint_size {
5911            description.push("maintainHintSize: false".to_owned());
5912        }
5913        if self.maintain_label_size {
5914            description.push("maintainLabelSize: true".to_owned());
5915        }
5916        if let Some(error) = &self.error {
5917            description.push(format!("error: \"{:?}\"", error));
5918        }
5919        if let Some(error_text) = &self.error_text {
5920            description.push(format!("errorText: \"{}\"", error_text));
5921        }
5922        if let Some(error_style) = &self.error_style {
5923            description.push(format!("errorStyle: \"{:?}\"", error_style));
5924        }
5925        if let Some(error_max_lines) = &self.error_max_lines {
5926            description.push(format!("errorMaxLines: \"{:?}\"", error_max_lines));
5927        }
5928        if let Some(floating_label_behavior) = &self.floating_label_behavior {
5929            description.push(format!(
5930                "floatingLabelBehavior: {:?}",
5931                floating_label_behavior
5932            ));
5933        }
5934        if let Some(floating_label_alignment) = &self.floating_label_alignment {
5935            description.push(format!(
5936                "floatingLabelAlignment: {:?}",
5937                floating_label_alignment
5938            ));
5939        }
5940        if self.is_dense.unwrap_or(false) {
5941            description.push(format!("isDense: {:?}", self.is_dense.expect("checked")));
5942        }
5943        if let Some(content_padding) = &self.content_padding {
5944            description.push(format!("contentPadding: {:?}", content_padding));
5945        }
5946        if self.is_collapsed.unwrap_or(false) {
5947            description.push(format!(
5948                "isCollapsed: {:?}",
5949                self.is_collapsed.expect("checked")
5950            ));
5951        }
5952        if let Some(prefix_icon) = &self.prefix_icon {
5953            description.push(format!("prefixIcon: {:?}", prefix_icon));
5954        }
5955        if let Some(prefix_icon_color) = &self.prefix_icon_color {
5956            description.push(format!("prefixIconColor: {:?}", prefix_icon_color));
5957        }
5958        if let Some(prefix) = &self.prefix {
5959            description.push(format!("prefix: {:?}", prefix));
5960        }
5961        if let Some(prefix_text) = &self.prefix_text {
5962            description.push(format!("prefixText: {}", prefix_text));
5963        }
5964        if let Some(prefix_style) = &self.prefix_style {
5965            description.push(format!("prefixStyle: {:?}", prefix_style));
5966        }
5967        if let Some(prefix_icon_constraints) = &self.prefix_icon_constraints {
5968            description.push(format!(
5969                "prefixIconConstraints: {:?}",
5970                prefix_icon_constraints
5971            ));
5972        }
5973        if let Some(suffix_icon) = &self.suffix_icon {
5974            description.push(format!("suffixIcon: {:?}", suffix_icon));
5975        }
5976        if let Some(suffix_icon_color) = &self.suffix_icon_color {
5977            description.push(format!("suffixIconColor: {:?}", suffix_icon_color));
5978        }
5979        if let Some(suffix) = &self.suffix {
5980            description.push(format!("suffix: {:?}", suffix));
5981        }
5982        if let Some(suffix_text) = &self.suffix_text {
5983            description.push(format!("suffixText: {}", suffix_text));
5984        }
5985        if let Some(suffix_style) = &self.suffix_style {
5986            description.push(format!("suffixStyle: {:?}", suffix_style));
5987        }
5988        if let Some(suffix_icon_constraints) = &self.suffix_icon_constraints {
5989            description.push(format!(
5990                "suffixIconConstraints: {:?}",
5991                suffix_icon_constraints
5992            ));
5993        }
5994        if let Some(counter) = &self.counter {
5995            description.push(format!("counter: {:?}", counter));
5996        }
5997        if let Some(counter_text) = &self.counter_text {
5998            description.push(format!("counterText: {}", counter_text));
5999        }
6000        if let Some(counter_style) = &self.counter_style {
6001            description.push(format!("counterStyle: {:?}", counter_style));
6002        }
6003        if self.filled.unwrap_or(false) {
6004            description.push("filled: true".to_owned());
6005        }
6006        if let Some(fill_color) = &self.fill_color {
6007            description.push(format!("fillColor: {:?}", fill_color));
6008        }
6009        if let Some(focus_color) = &self.focus_color {
6010            description.push(format!("focusColor: {:?}", focus_color));
6011        }
6012        if let Some(hover_color) = &self.hover_color {
6013            description.push(format!("hoverColor: {:?}", hover_color));
6014        }
6015        if let Some(error_border) = &self.error_border {
6016            description.push(format!("errorBorder: {:?}", error_border));
6017        }
6018        if let Some(focused_border) = &self.focused_border {
6019            description.push(format!("focusedBorder: {:?}", focused_border));
6020        }
6021        if let Some(focused_error_border) = &self.focused_error_border {
6022            description.push(format!("focusedErrorBorder: {:?}", focused_error_border));
6023        }
6024        if let Some(disabled_border) = &self.disabled_border {
6025            description.push(format!("disabledBorder: {:?}", disabled_border));
6026        }
6027        if let Some(enabled_border) = &self.enabled_border {
6028            description.push(format!("enabledBorder: {:?}", enabled_border));
6029        }
6030        if let Some(border) = &self.border {
6031            description.push(format!("border: {:?}", border));
6032        }
6033        if !self.enabled {
6034            description.push("enabled: false".to_owned());
6035        }
6036        if let Some(semantic_counter_text) = &self.semantic_counter_text {
6037            description.push(format!("semanticCounterText: {}", semantic_counter_text));
6038        }
6039        if let Some(align_label_with_hint) = &self.align_label_with_hint {
6040            description.push(format!("alignLabelWithHint: {:?}", align_label_with_hint));
6041        }
6042        if let Some(constraints) = &self.constraints {
6043            description.push(format!("constraints: {:?}", constraints));
6044        }
6045        if let Some(visual_density) = &self.visual_density {
6046            description.push(format!("visualDensity: {visual_density}"));
6047        }
6048        if let Some(supporting_text_padding) = &self.supporting_text_padding {
6049            description.push(format!(
6050                "supportingTextPadding: {:?}",
6051                supporting_text_padding
6052            ));
6053        }
6054        write!(f, "InputDecoration({})", description.join(", "))
6055    }
6056}
6057
6058/// Dart's `InputDecoration.toString`, which [`Debug`] already renders.
6059impl fmt::Display for InputDecoration {
6060    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6061        fmt::Debug::fmt(self, f)
6062    }
6063}
6064
6065/// Defines the default appearance of `InputDecorator`s.
6066///
6067/// Descendant widgets obtain the current theme's `InputDecorationThemeData` using
6068/// `InputDecorationTheme::of`. When a widget uses `InputDecorationTheme::of`, it is
6069/// automatically rebuilt if the theme later changes.
6070///
6071/// See also:
6072///
6073///  * `InputDecorationThemeData`, which describes the actual configuration of an
6074///    input decoration theme.
6075///  * `ThemeData::input_decoration_theme`, which specifies an input decoration theme as
6076///    part of the overall Material theme.
6077///
6078/// Dart's constructor takes either the properties or a [`data`](Self::data); here the
6079/// properties are the `with_*` setters and [`with_data`](Self::with_data) the other, and each
6080/// setter that breaks Dart's constructor assert (a `data` together with any property) fails in
6081/// a debug build. The getters are methods, as Dart's, hence the `with_` prefix.
6082#[derive(Clone, Debug)]
6083pub struct InputDecorationTheme {
6084    pub key: Option<KeyRef>,
6085    data: Option<InputDecorationThemeData>,
6086    label_style: Option<AnyTextStyle>,
6087    floating_label_style: Option<AnyTextStyle>,
6088    helper_style: Option<AnyTextStyle>,
6089    helper_max_lines: Option<i32>,
6090    hint_style: Option<AnyTextStyle>,
6091    hint_fade_duration: Option<Duration>,
6092    hint_max_lines: Option<i32>,
6093    error_style: Option<AnyTextStyle>,
6094    error_max_lines: Option<i32>,
6095    floating_label_behavior: Option<FloatingLabelBehavior>,
6096    floating_label_alignment: Option<FloatingLabelAlignment>,
6097    is_dense: Option<bool>,
6098    content_padding: Option<EdgeInsetsGeometry>,
6099    is_collapsed: Option<bool>,
6100    icon_color: Option<AnyColor>,
6101    prefix_style: Option<AnyTextStyle>,
6102    prefix_icon_color: Option<AnyColor>,
6103    prefix_icon_constraints: Option<BoxConstraints>,
6104    suffix_style: Option<AnyTextStyle>,
6105    suffix_icon_color: Option<AnyColor>,
6106    suffix_icon_constraints: Option<BoxConstraints>,
6107    counter_style: Option<AnyTextStyle>,
6108    filled: Option<bool>,
6109    fill_color: Option<AnyColor>,
6110    active_indicator_border: Option<AnyBorderSide>,
6111    outline_border: Option<AnyBorderSide>,
6112    focus_color: Option<Color>,
6113    hover_color: Option<Color>,
6114    error_border: Option<InputBorderRef>,
6115    focused_border: Option<InputBorderRef>,
6116    focused_error_border: Option<InputBorderRef>,
6117    disabled_border: Option<InputBorderRef>,
6118    enabled_border: Option<InputBorderRef>,
6119    border: Option<InputBorderRef>,
6120    align_label_with_hint: Option<bool>,
6121    constraints: Option<BoxConstraints>,
6122    visual_density: Option<VisualDensity>,
6123    child: WidgetRef,
6124}
6125
6126impl InputDecorationTheme {
6127    /// Creates a `InputDecorationTheme` that controls visual parameters for
6128    /// descendant `InputDecorator`s.
6129    pub fn new() -> InputDecorationTheme {
6130        InputDecorationTheme {
6131            key: None,
6132            data: None,
6133            label_style: None,
6134            floating_label_style: None,
6135            helper_style: None,
6136            helper_max_lines: None,
6137            hint_style: None,
6138            hint_fade_duration: None,
6139            hint_max_lines: None,
6140            error_style: None,
6141            error_max_lines: None,
6142            floating_label_behavior: None,
6143            floating_label_alignment: None,
6144            is_dense: None,
6145            content_padding: None,
6146            is_collapsed: None,
6147            icon_color: None,
6148            prefix_style: None,
6149            prefix_icon_color: None,
6150            prefix_icon_constraints: None,
6151            suffix_style: None,
6152            suffix_icon_color: None,
6153            suffix_icon_constraints: None,
6154            counter_style: None,
6155            filled: None,
6156            fill_color: None,
6157            active_indicator_border: None,
6158            outline_border: None,
6159            focus_color: None,
6160            hover_color: None,
6161            error_border: None,
6162            focused_border: None,
6163            focused_error_border: None,
6164            disabled_border: None,
6165            enabled_border: None,
6166            border: None,
6167            align_label_with_hint: None,
6168            constraints: None,
6169            visual_density: None,
6170            child: SizedBox::shrink().into_widget(),
6171        }
6172    }
6173
6174    /// Dart `InputDecorationTheme(key:)`.
6175    pub fn key(mut self, key: KeyRef) -> InputDecorationTheme {
6176        self.key = Some(key);
6177        self
6178    }
6179
6180    /// Dart `InputDecorationTheme(child:)`; the default is `SizedBox::shrink()`.
6181    #[cfg_attr(debug_assertions, track_caller)]
6182    pub fn child<K>(mut self, child: impl IntoWidget<K>) -> InputDecorationTheme {
6183        self.child = child.into_widget();
6184        self
6185    }
6186
6187    /// Dart `InputDecorationTheme(data:)`.
6188    pub fn with_data(mut self, data: InputDecorationThemeData) -> InputDecorationTheme {
6189        debug_assert!(self.has_no_property());
6190        self.data = Some(data);
6191        self
6192    }
6193
6194    /// Dart `InputDecorationTheme(labelStyle:)`.
6195    pub fn with_label_style(
6196        mut self,
6197        label_style: impl Into<AnyTextStyle>,
6198    ) -> InputDecorationTheme {
6199        debug_assert!(self.data.is_none());
6200        self.label_style = Some(label_style.into());
6201        self
6202    }
6203
6204    /// Dart `InputDecorationTheme(floatingLabelStyle:)`.
6205    pub fn with_floating_label_style(
6206        mut self,
6207        floating_label_style: impl Into<AnyTextStyle>,
6208    ) -> InputDecorationTheme {
6209        debug_assert!(self.data.is_none());
6210        self.floating_label_style = Some(floating_label_style.into());
6211        self
6212    }
6213
6214    /// Dart `InputDecorationTheme(helperStyle:)`.
6215    pub fn with_helper_style(
6216        mut self,
6217        helper_style: impl Into<AnyTextStyle>,
6218    ) -> InputDecorationTheme {
6219        debug_assert!(self.data.is_none());
6220        self.helper_style = Some(helper_style.into());
6221        self
6222    }
6223
6224    /// Dart `InputDecorationTheme(helperMaxLines:)`.
6225    pub fn with_helper_max_lines(mut self, helper_max_lines: i32) -> InputDecorationTheme {
6226        debug_assert!(self.data.is_none());
6227        self.helper_max_lines = Some(helper_max_lines);
6228        self
6229    }
6230
6231    /// Dart `InputDecorationTheme(hintStyle:)`.
6232    pub fn with_hint_style(mut self, hint_style: impl Into<AnyTextStyle>) -> InputDecorationTheme {
6233        debug_assert!(self.data.is_none());
6234        self.hint_style = Some(hint_style.into());
6235        self
6236    }
6237
6238    /// Dart `InputDecorationTheme(hintFadeDuration:)`.
6239    pub fn with_hint_fade_duration(mut self, hint_fade_duration: Duration) -> InputDecorationTheme {
6240        debug_assert!(self.data.is_none());
6241        self.hint_fade_duration = Some(hint_fade_duration);
6242        self
6243    }
6244
6245    /// Dart `InputDecorationTheme(hintMaxLines:)`.
6246    pub fn with_hint_max_lines(mut self, hint_max_lines: i32) -> InputDecorationTheme {
6247        debug_assert!(self.data.is_none());
6248        self.hint_max_lines = Some(hint_max_lines);
6249        self
6250    }
6251
6252    /// Dart `InputDecorationTheme(errorStyle:)`.
6253    pub fn with_error_style(
6254        mut self,
6255        error_style: impl Into<AnyTextStyle>,
6256    ) -> InputDecorationTheme {
6257        debug_assert!(self.data.is_none());
6258        self.error_style = Some(error_style.into());
6259        self
6260    }
6261
6262    /// Dart `InputDecorationTheme(errorMaxLines:)`.
6263    pub fn with_error_max_lines(mut self, error_max_lines: i32) -> InputDecorationTheme {
6264        debug_assert!(self.data.is_none());
6265        self.error_max_lines = Some(error_max_lines);
6266        self
6267    }
6268
6269    /// Dart `InputDecorationTheme(floatingLabelBehavior:)`.
6270    pub fn with_floating_label_behavior(
6271        mut self,
6272        floating_label_behavior: FloatingLabelBehavior,
6273    ) -> InputDecorationTheme {
6274        debug_assert!(self.data.is_none());
6275        self.floating_label_behavior = Some(floating_label_behavior);
6276        self
6277    }
6278
6279    /// Dart `InputDecorationTheme(floatingLabelAlignment:)`.
6280    pub fn with_floating_label_alignment(
6281        mut self,
6282        floating_label_alignment: FloatingLabelAlignment,
6283    ) -> InputDecorationTheme {
6284        debug_assert!(self.data.is_none());
6285        self.floating_label_alignment = Some(floating_label_alignment);
6286        self
6287    }
6288
6289    /// Dart `InputDecorationTheme(isDense:)`.
6290    pub fn with_is_dense(mut self, is_dense: bool) -> InputDecorationTheme {
6291        debug_assert!(self.data.is_none());
6292        self.is_dense = Some(is_dense);
6293        self
6294    }
6295
6296    /// Dart `InputDecorationTheme(contentPadding:)`.
6297    pub fn with_content_padding(
6298        mut self,
6299        content_padding: impl Into<EdgeInsetsGeometry>,
6300    ) -> InputDecorationTheme {
6301        let content_padding = content_padding.into();
6302        debug_assert!(self.data.is_none());
6303        self.content_padding = Some(content_padding);
6304        self
6305    }
6306
6307    /// Dart `InputDecorationTheme(isCollapsed:)`.
6308    pub fn with_is_collapsed(mut self, is_collapsed: bool) -> InputDecorationTheme {
6309        debug_assert!(self.data.is_none());
6310        self.is_collapsed = Some(is_collapsed);
6311        self
6312    }
6313
6314    /// Dart `InputDecorationTheme(iconColor:)`.
6315    pub fn with_icon_color(mut self, icon_color: impl Into<AnyColor>) -> InputDecorationTheme {
6316        debug_assert!(self.data.is_none());
6317        self.icon_color = Some(icon_color.into());
6318        self
6319    }
6320
6321    /// Dart `InputDecorationTheme(prefixStyle:)`.
6322    pub fn with_prefix_style(
6323        mut self,
6324        prefix_style: impl Into<AnyTextStyle>,
6325    ) -> InputDecorationTheme {
6326        debug_assert!(self.data.is_none());
6327        self.prefix_style = Some(prefix_style.into());
6328        self
6329    }
6330
6331    /// Dart `InputDecorationTheme(prefixIconColor:)`.
6332    pub fn with_prefix_icon_color(
6333        mut self,
6334        prefix_icon_color: impl Into<AnyColor>,
6335    ) -> InputDecorationTheme {
6336        debug_assert!(self.data.is_none());
6337        self.prefix_icon_color = Some(prefix_icon_color.into());
6338        self
6339    }
6340
6341    /// Dart `InputDecorationTheme(prefixIconConstraints:)`.
6342    pub fn with_prefix_icon_constraints(
6343        mut self,
6344        prefix_icon_constraints: BoxConstraints,
6345    ) -> InputDecorationTheme {
6346        debug_assert!(self.data.is_none());
6347        self.prefix_icon_constraints = Some(prefix_icon_constraints);
6348        self
6349    }
6350
6351    /// Dart `InputDecorationTheme(suffixStyle:)`.
6352    pub fn with_suffix_style(
6353        mut self,
6354        suffix_style: impl Into<AnyTextStyle>,
6355    ) -> InputDecorationTheme {
6356        debug_assert!(self.data.is_none());
6357        self.suffix_style = Some(suffix_style.into());
6358        self
6359    }
6360
6361    /// Dart `InputDecorationTheme(suffixIconColor:)`.
6362    pub fn with_suffix_icon_color(
6363        mut self,
6364        suffix_icon_color: impl Into<AnyColor>,
6365    ) -> InputDecorationTheme {
6366        debug_assert!(self.data.is_none());
6367        self.suffix_icon_color = Some(suffix_icon_color.into());
6368        self
6369    }
6370
6371    /// Dart `InputDecorationTheme(suffixIconConstraints:)`.
6372    pub fn with_suffix_icon_constraints(
6373        mut self,
6374        suffix_icon_constraints: BoxConstraints,
6375    ) -> InputDecorationTheme {
6376        debug_assert!(self.data.is_none());
6377        self.suffix_icon_constraints = Some(suffix_icon_constraints);
6378        self
6379    }
6380
6381    /// Dart `InputDecorationTheme(counterStyle:)`.
6382    pub fn with_counter_style(
6383        mut self,
6384        counter_style: impl Into<AnyTextStyle>,
6385    ) -> InputDecorationTheme {
6386        debug_assert!(self.data.is_none());
6387        self.counter_style = Some(counter_style.into());
6388        self
6389    }
6390
6391    /// Dart `InputDecorationTheme(filled:)`.
6392    pub fn with_filled(mut self, filled: bool) -> InputDecorationTheme {
6393        debug_assert!(self.data.is_none());
6394        self.filled = Some(filled);
6395        self
6396    }
6397
6398    /// Dart `InputDecorationTheme(fillColor:)`.
6399    pub fn with_fill_color(mut self, fill_color: impl Into<AnyColor>) -> InputDecorationTheme {
6400        debug_assert!(self.data.is_none());
6401        self.fill_color = Some(fill_color.into());
6402        self
6403    }
6404
6405    /// Dart `InputDecorationTheme(activeIndicatorBorder:)`.
6406    pub fn with_active_indicator_border(
6407        mut self,
6408        active_indicator_border: impl Into<AnyBorderSide>,
6409    ) -> InputDecorationTheme {
6410        debug_assert!(self.data.is_none());
6411        self.active_indicator_border = Some(active_indicator_border.into());
6412        self
6413    }
6414
6415    /// Dart `InputDecorationTheme(outlineBorder:)`.
6416    pub fn with_outline_border(
6417        mut self,
6418        outline_border: impl Into<AnyBorderSide>,
6419    ) -> InputDecorationTheme {
6420        debug_assert!(self.data.is_none());
6421        self.outline_border = Some(outline_border.into());
6422        self
6423    }
6424
6425    /// Dart `InputDecorationTheme(focusColor:)`.
6426    pub fn with_focus_color(mut self, focus_color: Color) -> InputDecorationTheme {
6427        debug_assert!(self.data.is_none());
6428        self.focus_color = Some(focus_color);
6429        self
6430    }
6431
6432    /// Dart `InputDecorationTheme(hoverColor:)`.
6433    pub fn with_hover_color(mut self, hover_color: Color) -> InputDecorationTheme {
6434        debug_assert!(self.data.is_none());
6435        self.hover_color = Some(hover_color);
6436        self
6437    }
6438
6439    /// Dart `InputDecorationTheme(errorBorder:)`.
6440    pub fn with_error_border(
6441        mut self,
6442        error_border: impl Into<InputBorderRef>,
6443    ) -> InputDecorationTheme {
6444        debug_assert!(self.data.is_none());
6445        self.error_border = Some(error_border.into());
6446        self
6447    }
6448
6449    /// Dart `InputDecorationTheme(focusedBorder:)`.
6450    pub fn with_focused_border(
6451        mut self,
6452        focused_border: impl Into<InputBorderRef>,
6453    ) -> InputDecorationTheme {
6454        debug_assert!(self.data.is_none());
6455        self.focused_border = Some(focused_border.into());
6456        self
6457    }
6458
6459    /// Dart `InputDecorationTheme(focusedErrorBorder:)`.
6460    pub fn with_focused_error_border(
6461        mut self,
6462        focused_error_border: impl Into<InputBorderRef>,
6463    ) -> InputDecorationTheme {
6464        debug_assert!(self.data.is_none());
6465        self.focused_error_border = Some(focused_error_border.into());
6466        self
6467    }
6468
6469    /// Dart `InputDecorationTheme(disabledBorder:)`.
6470    pub fn with_disabled_border(
6471        mut self,
6472        disabled_border: impl Into<InputBorderRef>,
6473    ) -> InputDecorationTheme {
6474        debug_assert!(self.data.is_none());
6475        self.disabled_border = Some(disabled_border.into());
6476        self
6477    }
6478
6479    /// Dart `InputDecorationTheme(enabledBorder:)`.
6480    pub fn with_enabled_border(
6481        mut self,
6482        enabled_border: impl Into<InputBorderRef>,
6483    ) -> InputDecorationTheme {
6484        debug_assert!(self.data.is_none());
6485        self.enabled_border = Some(enabled_border.into());
6486        self
6487    }
6488
6489    /// Dart `InputDecorationTheme(border:)`.
6490    pub fn with_border(mut self, border: impl Into<InputBorderRef>) -> InputDecorationTheme {
6491        debug_assert!(self.data.is_none());
6492        self.border = Some(border.into());
6493        self
6494    }
6495
6496    /// Dart `InputDecorationTheme(alignLabelWithHint:)`.
6497    pub fn with_align_label_with_hint(
6498        mut self,
6499        align_label_with_hint: bool,
6500    ) -> InputDecorationTheme {
6501        debug_assert!(self.data.is_none());
6502        self.align_label_with_hint = Some(align_label_with_hint);
6503        self
6504    }
6505
6506    /// Dart `InputDecorationTheme(constraints:)`.
6507    pub fn with_constraints(mut self, constraints: BoxConstraints) -> InputDecorationTheme {
6508        debug_assert!(self.data.is_none());
6509        self.constraints = Some(constraints);
6510        self
6511    }
6512
6513    /// Dart `InputDecorationTheme(visualDensity:)`.
6514    pub fn with_visual_density(mut self, visual_density: VisualDensity) -> InputDecorationTheme {
6515        debug_assert!(self.data.is_none());
6516        self.visual_density = Some(visual_density);
6517        self
6518    }
6519
6520    /// Overrides the default value for `InputDecoration::label_style`.
6521    ///
6522    /// This property is obsolete and will be deprecated in a future release:
6523    /// please use the `InputDecorationThemeData::label_style` property in `data` instead.
6524    pub fn label_style(&self) -> Option<AnyTextStyle> {
6525        match &self.data {
6526            Some(data) => data.label_style.clone(),
6527            None => self.label_style.clone(),
6528        }
6529    }
6530
6531    /// Overrides the default value for `InputDecoration::floating_label_style`.
6532    ///
6533    /// This property is obsolete and will be deprecated in a future release:
6534    /// please use the `InputDecorationThemeData::floating_label_style` property in `data` instead.
6535    pub fn floating_label_style(&self) -> Option<AnyTextStyle> {
6536        match &self.data {
6537            Some(data) => data.floating_label_style.clone(),
6538            None => self.floating_label_style.clone(),
6539        }
6540    }
6541
6542    /// Overrides the default value for `InputDecoration::floating_label_style`.
6543    ///
6544    /// This property is obsolete and will be deprecated in a future release:
6545    /// please use the `InputDecorationThemeData::helper_style` property in `data` instead.
6546    pub fn helper_style(&self) -> Option<AnyTextStyle> {
6547        match &self.data {
6548            Some(data) => data.helper_style.clone(),
6549            None => self.helper_style.clone(),
6550        }
6551    }
6552
6553    /// Overrides the default value for `InputDecoration::helper_max_lines`.
6554    ///
6555    /// This property is obsolete and will be deprecated in a future release:
6556    /// please use the `InputDecorationThemeData::helper_max_lines` property in `data` instead.
6557    pub fn helper_max_lines(&self) -> Option<i32> {
6558        match &self.data {
6559            Some(data) => data.helper_max_lines,
6560            None => self.helper_max_lines,
6561        }
6562    }
6563
6564    /// Overrides the default value for `InputDecoration::hint_style`.
6565    ///
6566    /// This property is obsolete and will be deprecated in a future release:
6567    /// please use the `InputDecorationThemeData::hint_style` property in `data` instead.
6568    pub fn hint_style(&self) -> Option<AnyTextStyle> {
6569        match &self.data {
6570            Some(data) => data.hint_style.clone(),
6571            None => self.hint_style.clone(),
6572        }
6573    }
6574
6575    /// Overrides the default value for `InputDecoration::hint_fade_duration`.
6576    ///
6577    /// This property is obsolete and will be deprecated in a future release:
6578    /// please use the `InputDecorationThemeData::hint_fade_duration` property in `data` instead.
6579    pub fn hint_fade_duration(&self) -> Option<Duration> {
6580        match &self.data {
6581            Some(data) => data.hint_fade_duration,
6582            None => self.hint_fade_duration,
6583        }
6584    }
6585
6586    /// Overrides the default value for `InputDecoration::hint_max_lines`.
6587    ///
6588    /// This property is obsolete and will be deprecated in a future release:
6589    /// please use the `InputDecorationThemeData::hint_max_lines` property in `data` instead.
6590    pub fn hint_max_lines(&self) -> Option<i32> {
6591        match &self.data {
6592            Some(data) => data.hint_max_lines,
6593            None => self.hint_max_lines,
6594        }
6595    }
6596
6597    /// Overrides the default value for `InputDecoration::error_style`.
6598    ///
6599    /// This property is obsolete and will be deprecated in a future release:
6600    /// please use the `InputDecorationThemeData::error_style` property in `data` instead.
6601    pub fn error_style(&self) -> Option<AnyTextStyle> {
6602        match &self.data {
6603            Some(data) => data.error_style.clone(),
6604            None => self.error_style.clone(),
6605        }
6606    }
6607
6608    /// Overrides the default value for `InputDecoration::error_max_lines`.
6609    ///
6610    /// This property is obsolete and will be deprecated in a future release:
6611    /// please use the `InputDecorationThemeData::error_max_lines` property in `data` instead.
6612    pub fn error_max_lines(&self) -> Option<i32> {
6613        match &self.data {
6614            Some(data) => data.error_max_lines,
6615            None => self.error_max_lines,
6616        }
6617    }
6618
6619    /// Overrides the default value for `InputDecoration::floating_label_behavior`.
6620    ///
6621    /// This property is obsolete and will be deprecated in a future release:
6622    /// please use the `InputDecorationThemeData::floating_label_behavior` property in `data` instead.
6623    pub fn floating_label_behavior(&self) -> FloatingLabelBehavior {
6624        match &self.data {
6625            Some(data) => data.floating_label_behavior,
6626            None => self
6627                .floating_label_behavior
6628                .unwrap_or(FloatingLabelBehavior::Auto),
6629        }
6630    }
6631
6632    /// Overrides the default value for `InputDecoration::floating_label_alignment`.
6633    ///
6634    /// This property is obsolete and will be deprecated in a future release:
6635    /// please use the `InputDecorationThemeData::floating_label_alignment` property in `data` instead.
6636    pub fn floating_label_alignment(&self) -> FloatingLabelAlignment {
6637        match &self.data {
6638            Some(data) => data.floating_label_alignment,
6639            None => self
6640                .floating_label_alignment
6641                .unwrap_or(FloatingLabelAlignment::START),
6642        }
6643    }
6644
6645    /// Overrides the default value for `InputDecoration::is_dense`.
6646    ///
6647    /// This property is obsolete and will be deprecated in a future release:
6648    /// please use the `InputDecorationThemeData::is_dense` property in `data` instead.
6649    pub fn is_dense(&self) -> bool {
6650        match &self.data {
6651            Some(data) => data.is_dense,
6652            None => self.is_dense.unwrap_or(false),
6653        }
6654    }
6655
6656    /// Overrides the default value for `InputDecoration::content_padding`.
6657    ///
6658    /// This property is obsolete and will be deprecated in a future release:
6659    /// please use the `InputDecorationThemeData::content_padding` property in `data` instead.
6660    pub fn content_padding(&self) -> Option<EdgeInsetsGeometry> {
6661        match &self.data {
6662            Some(data) => data.content_padding,
6663            None => self.content_padding,
6664        }
6665    }
6666
6667    /// Overrides the default value for `InputDecoration::is_collapsed`.
6668    ///
6669    /// This property is obsolete and will be deprecated in a future release:
6670    /// please use the `InputDecorationThemeData::is_collapsed` property in `data` instead.
6671    pub fn is_collapsed(&self) -> bool {
6672        match &self.data {
6673            Some(data) => data.is_collapsed,
6674            None => self.is_collapsed.unwrap_or(false),
6675        }
6676    }
6677
6678    /// Overrides the default value for `InputDecoration::icon_color`.
6679    ///
6680    /// This property is obsolete and will be deprecated in a future release:
6681    /// please use the `InputDecorationThemeData::icon_color` property in `data` instead.
6682    pub fn icon_color(&self) -> Option<AnyColor> {
6683        match &self.data {
6684            Some(data) => data.icon_color.clone(),
6685            None => self.icon_color.clone(),
6686        }
6687    }
6688
6689    /// Overrides the default value for `InputDecoration::prefix_style`.
6690    ///
6691    /// This property is obsolete and will be deprecated in a future release:
6692    /// please use the `InputDecorationThemeData::prefix_style` property in `data` instead.
6693    pub fn prefix_style(&self) -> Option<AnyTextStyle> {
6694        match &self.data {
6695            Some(data) => data.prefix_style.clone(),
6696            None => self.prefix_style.clone(),
6697        }
6698    }
6699
6700    /// Overrides the default value for `InputDecoration::prefix_icon_color`.
6701    ///
6702    /// This property is obsolete and will be deprecated in a future release:
6703    /// please use the `InputDecorationThemeData::prefix_icon_color` property in `data` instead.
6704    pub fn prefix_icon_color(&self) -> Option<AnyColor> {
6705        match &self.data {
6706            Some(data) => data.prefix_icon_color.clone(),
6707            None => self.prefix_icon_color.clone(),
6708        }
6709    }
6710
6711    /// Overrides the default value for `InputDecoration::prefix_icon_constraints`.
6712    ///
6713    /// This property is obsolete and will be deprecated in a future release:
6714    /// please use the `InputDecorationThemeData::prefix_icon_constraints` property in `data` instead.
6715    pub fn prefix_icon_constraints(&self) -> Option<BoxConstraints> {
6716        match &self.data {
6717            Some(data) => data.prefix_icon_constraints,
6718            None => self.prefix_icon_constraints,
6719        }
6720    }
6721
6722    /// Overrides the default value for `InputDecoration::suffix_style`.
6723    ///
6724    /// This property is obsolete and will be deprecated in a future release:
6725    /// please use the `InputDecorationThemeData::suffix_style` property in `data` instead.
6726    pub fn suffix_style(&self) -> Option<AnyTextStyle> {
6727        match &self.data {
6728            Some(data) => data.suffix_style.clone(),
6729            None => self.suffix_style.clone(),
6730        }
6731    }
6732
6733    /// Overrides the default value for `InputDecoration::suffix_icon_color`.
6734    ///
6735    /// This property is obsolete and will be deprecated in a future release:
6736    /// please use the `InputDecorationThemeData::suffix_icon_color` property in `data` instead.
6737    pub fn suffix_icon_color(&self) -> Option<AnyColor> {
6738        match &self.data {
6739            Some(data) => data.suffix_icon_color.clone(),
6740            None => self.suffix_icon_color.clone(),
6741        }
6742    }
6743
6744    /// Overrides the default value for `InputDecoration::suffix_icon_constraints`.
6745    ///
6746    /// This property is obsolete and will be deprecated in a future release:
6747    /// please use the `InputDecorationThemeData::suffix_icon_constraints` property in `data` instead.
6748    pub fn suffix_icon_constraints(&self) -> Option<BoxConstraints> {
6749        match &self.data {
6750            Some(data) => data.suffix_icon_constraints,
6751            None => self.suffix_icon_constraints,
6752        }
6753    }
6754
6755    /// Overrides the default value for `InputDecoration::counter_style`.
6756    ///
6757    /// This property is obsolete and will be deprecated in a future release:
6758    /// please use the `InputDecorationThemeData::counter_style` property in `data` instead.
6759    pub fn counter_style(&self) -> Option<AnyTextStyle> {
6760        match &self.data {
6761            Some(data) => data.counter_style.clone(),
6762            None => self.counter_style.clone(),
6763        }
6764    }
6765
6766    /// Overrides the default value for `InputDecoration::filled`.
6767    ///
6768    /// This property is obsolete and will be deprecated in a future release:
6769    /// please use the `InputDecorationThemeData::filled` property in `data` instead.
6770    pub fn filled(&self) -> bool {
6771        match &self.data {
6772            Some(data) => data.filled,
6773            None => self.filled.unwrap_or(false),
6774        }
6775    }
6776
6777    /// Overrides the default value for `InputDecoration::fill_color`.
6778    ///
6779    /// This property is obsolete and will be deprecated in a future release:
6780    /// please use the `InputDecorationThemeData::fill_color` property in `data` instead.
6781    pub fn fill_color(&self) -> Option<AnyColor> {
6782        match &self.data {
6783            Some(data) => data.fill_color.clone(),
6784            None => self.fill_color.clone(),
6785        }
6786    }
6787
6788    /// The borderSide of the UnderlineInputBorder with `color` and `weight`.
6789    ///
6790    /// This property is obsolete and will be deprecated in a future release:
6791    /// please use the `InputDecorationThemeData::active_indicator_border` property in `data` instead.
6792    pub fn active_indicator_border(&self) -> Option<AnyBorderSide> {
6793        match &self.data {
6794            Some(data) => data.active_indicator_border.clone(),
6795            None => self.active_indicator_border.clone(),
6796        }
6797    }
6798
6799    /// The borderSide of the OutlineInputBorder with `color` and `weight`.
6800    ///
6801    /// This property is obsolete and will be deprecated in a future release:
6802    /// please use the `InputDecorationThemeData::outline_border` property in `data` instead.
6803    pub fn outline_border(&self) -> Option<AnyBorderSide> {
6804        match &self.data {
6805            Some(data) => data.outline_border.clone(),
6806            None => self.outline_border.clone(),
6807        }
6808    }
6809
6810    /// Overrides the default value for `InputDecoration::focus_color`.
6811    ///
6812    /// This property is obsolete and will be deprecated in a future release:
6813    /// please use the `InputDecorationThemeData::focus_color` property in `data` instead.
6814    pub fn focus_color(&self) -> Option<Color> {
6815        match &self.data {
6816            Some(data) => data.focus_color,
6817            None => self.focus_color,
6818        }
6819    }
6820
6821    /// Overrides the default value for `InputDecoration::hover_color`.
6822    ///
6823    /// This property is obsolete and will be deprecated in a future release:
6824    /// please use the `InputDecorationThemeData::hover_color` property in `data` instead.
6825    pub fn hover_color(&self) -> Option<Color> {
6826        match &self.data {
6827            Some(data) => data.hover_color,
6828            None => self.hover_color,
6829        }
6830    }
6831
6832    /// Overrides the default value for `InputDecoration::error_border`.
6833    ///
6834    /// This property is obsolete and will be deprecated in a future release:
6835    /// please use the `InputDecorationThemeData::error_border` property in `data` instead.
6836    pub fn error_border(&self) -> Option<&InputBorderRef> {
6837        match &self.data {
6838            Some(data) => data.error_border.as_ref(),
6839            None => self.error_border.as_ref(),
6840        }
6841    }
6842
6843    /// Overrides the default value for `InputDecoration::focused_border`.
6844    ///
6845    /// This property is obsolete and will be deprecated in a future release:
6846    /// please use the `InputDecorationThemeData::focused_border` property in `data` instead.
6847    pub fn focused_border(&self) -> Option<&InputBorderRef> {
6848        match &self.data {
6849            Some(data) => data.focused_border.as_ref(),
6850            None => self.focused_border.as_ref(),
6851        }
6852    }
6853
6854    /// Overrides the default value for `InputDecoration::focused_error_border`.
6855    ///
6856    /// This property is obsolete and will be deprecated in a future release:
6857    /// please use the `InputDecorationThemeData::focused_error_border` property in `data` instead.
6858    pub fn focused_error_border(&self) -> Option<&InputBorderRef> {
6859        match &self.data {
6860            Some(data) => data.focused_error_border.as_ref(),
6861            None => self.focused_error_border.as_ref(),
6862        }
6863    }
6864
6865    /// Overrides the default value for `InputDecoration::disabled_border`.
6866    ///
6867    /// This property is obsolete and will be deprecated in a future release:
6868    /// please use the `InputDecorationThemeData::disabled_border` property in `data` instead.
6869    pub fn disabled_border(&self) -> Option<&InputBorderRef> {
6870        match &self.data {
6871            Some(data) => data.disabled_border.as_ref(),
6872            None => self.disabled_border.as_ref(),
6873        }
6874    }
6875
6876    /// Overrides the default value for `InputDecoration::enabled_border`.
6877    ///
6878    /// This property is obsolete and will be deprecated in a future release:
6879    /// please use the `InputDecorationThemeData::enabled_border` property in `data` instead.
6880    pub fn enabled_border(&self) -> Option<&InputBorderRef> {
6881        match &self.data {
6882            Some(data) => data.enabled_border.as_ref(),
6883            None => self.enabled_border.as_ref(),
6884        }
6885    }
6886
6887    /// Overrides the default value for `InputDecoration::border`.
6888    ///
6889    /// This property is obsolete and will be deprecated in a future release:
6890    /// please use the `InputDecorationThemeData::border` property in `data` instead.
6891    pub fn border(&self) -> Option<&InputBorderRef> {
6892        match &self.data {
6893            Some(data) => data.border.as_ref(),
6894            None => self.border.as_ref(),
6895        }
6896    }
6897
6898    /// Overrides the default value for `InputDecoration::align_label_with_hint`.
6899    ///
6900    /// This property is obsolete and will be deprecated in a future release:
6901    /// please use the `InputDecorationThemeData::align_label_with_hint` property in `data` instead.
6902    pub fn align_label_with_hint(&self) -> bool {
6903        match &self.data {
6904            Some(data) => data.align_label_with_hint,
6905            None => self.align_label_with_hint.unwrap_or(false),
6906        }
6907    }
6908
6909    /// Overrides the default value for `InputDecoration::constraints`.
6910    ///
6911    /// This property is obsolete and will be deprecated in a future release:
6912    /// please use the `InputDecorationThemeData::constraints` property in `data` instead.
6913    pub fn constraints(&self) -> Option<BoxConstraints> {
6914        match &self.data {
6915            Some(data) => data.constraints,
6916            None => self.constraints,
6917        }
6918    }
6919
6920    /// Overrides the default value for `InputDecoration::visual_density`.
6921    ///
6922    /// This property is obsolete and will be deprecated in a future release:
6923    /// please use the `InputDecorationThemeData::visual_density` property in `data` instead.
6924    pub fn visual_density(&self) -> Option<VisualDensity> {
6925        match &self.data {
6926            Some(data) => data.visual_density,
6927            None => self.visual_density,
6928        }
6929    }
6930
6931    /// The properties used for all descendant `TabBar` widgets.
6932    pub fn data(&self) -> InputDecorationThemeData {
6933        self.data
6934            .clone()
6935            .unwrap_or_else(|| InputDecorationThemeData {
6936                label_style: self.label_style.clone(),
6937                floating_label_style: self.floating_label_style.clone(),
6938                helper_style: self.helper_style.clone(),
6939                helper_max_lines: self.helper_max_lines,
6940                hint_style: self.hint_style.clone(),
6941                hint_fade_duration: self.hint_fade_duration,
6942                hint_max_lines: self.hint_max_lines,
6943                error_style: self.error_style.clone(),
6944                error_max_lines: self.error_max_lines,
6945                floating_label_behavior: self
6946                    .floating_label_behavior
6947                    .unwrap_or(FloatingLabelBehavior::Auto),
6948                floating_label_alignment: self
6949                    .floating_label_alignment
6950                    .unwrap_or(FloatingLabelAlignment::START),
6951                is_dense: self.is_dense.unwrap_or(false),
6952                content_padding: self.content_padding,
6953                is_collapsed: self.is_collapsed.unwrap_or(false),
6954                icon_color: self.icon_color.clone(),
6955                prefix_style: self.prefix_style.clone(),
6956                prefix_icon_color: self.prefix_icon_color.clone(),
6957                prefix_icon_constraints: self.prefix_icon_constraints,
6958                suffix_style: self.suffix_style.clone(),
6959                suffix_icon_color: self.suffix_icon_color.clone(),
6960                suffix_icon_constraints: self.suffix_icon_constraints,
6961                counter_style: self.counter_style.clone(),
6962                filled: self.filled.unwrap_or(false),
6963                fill_color: self.fill_color.clone(),
6964                active_indicator_border: self.active_indicator_border.clone(),
6965                outline_border: self.outline_border.clone(),
6966                focus_color: self.focus_color,
6967                hover_color: self.hover_color,
6968                error_border: self.error_border.clone(),
6969                focused_border: self.focused_border.clone(),
6970                focused_error_border: self.focused_error_border.clone(),
6971                disabled_border: self.disabled_border.clone(),
6972                enabled_border: self.enabled_border.clone(),
6973                border: self.border.clone(),
6974                align_label_with_hint: self.align_label_with_hint.unwrap_or(false),
6975                constraints: self.constraints,
6976                visual_density: self.visual_density,
6977                supporting_text_padding: None,
6978            })
6979    }
6980
6981    /// Returns the closest `InputDecorationThemeData` instance given the build context.
6982    ///
6983    /// If there is no enclosing `InputDecorationTheme` widget, then
6984    /// `ThemeData::input_decoration_theme` is used.
6985    ///
6986    /// Typical usage is as follows:
6987    ///
6988    /// ```text
6989    /// InputDecorationThemeData theme = InputDecorationTheme.of(context);
6990    /// ```
6991    pub fn of(app: &mut App, context: BuildContext) -> InputDecorationThemeData {
6992        match context.depend_on_inherited_widget_of_exact_type::<InputDecorationTheme>(app) {
6993            Some(input_decoration_theme) => input_decoration_theme.data(),
6994            None => Theme::of(app, context).input_decoration_theme.clone(),
6995        }
6996    }
6997
6998    /// Creates a copy of this object but with the given fields replaced with the
6999    /// new values.
7000    ///
7001    /// This method is obsolete and will be deprecated in a future release:
7002    /// please use the `InputDecorationThemeData::copy_with` instead.
7003    ///
7004    /// Dart's named arguments are the `with_*` setters on the copy
7005    /// (`theme.copy_with().with_is_dense(true)`). As in Dart, the copy carries neither the key
7006    /// nor the child, and holds the properties, never a [`data`](Self::data).
7007    pub fn copy_with(&self) -> InputDecorationTheme {
7008        InputDecorationTheme {
7009            key: None,
7010            data: None,
7011            label_style: self.label_style(),
7012            floating_label_style: self.floating_label_style(),
7013            helper_style: self.helper_style(),
7014            helper_max_lines: self.helper_max_lines(),
7015            hint_style: self.hint_style(),
7016            hint_fade_duration: self.hint_fade_duration(),
7017            hint_max_lines: self.hint_max_lines(),
7018            error_style: self.error_style(),
7019            error_max_lines: self.error_max_lines(),
7020            floating_label_behavior: Some(self.floating_label_behavior()),
7021            floating_label_alignment: Some(self.floating_label_alignment()),
7022            is_dense: Some(self.is_dense()),
7023            content_padding: self.content_padding(),
7024            is_collapsed: Some(self.is_collapsed()),
7025            icon_color: self.icon_color(),
7026            prefix_style: self.prefix_style(),
7027            prefix_icon_color: self.prefix_icon_color(),
7028            prefix_icon_constraints: self.prefix_icon_constraints(),
7029            suffix_style: self.suffix_style(),
7030            suffix_icon_color: self.suffix_icon_color(),
7031            suffix_icon_constraints: self.suffix_icon_constraints(),
7032            counter_style: self.counter_style(),
7033            filled: Some(self.filled()),
7034            fill_color: self.fill_color(),
7035            active_indicator_border: self.active_indicator_border(),
7036            outline_border: self.outline_border(),
7037            focus_color: self.focus_color(),
7038            hover_color: self.hover_color(),
7039            error_border: self.error_border().cloned(),
7040            focused_border: self.focused_border().cloned(),
7041            focused_error_border: self.focused_error_border().cloned(),
7042            disabled_border: self.disabled_border().cloned(),
7043            enabled_border: self.enabled_border().cloned(),
7044            border: self.border().cloned(),
7045            align_label_with_hint: Some(self.align_label_with_hint()),
7046            constraints: self.constraints(),
7047            visual_density: self.visual_density(),
7048            child: SizedBox::shrink().into_widget(),
7049        }
7050    }
7051
7052    /// Returns a copy of this InputDecorationTheme where the non-null fields in
7053    /// the given InputDecorationTheme override the corresponding nullable fields
7054    /// in this InputDecorationTheme.
7055    ///
7056    /// The non-nullable fields of InputDecorationTheme, such as `floating_label_behavior`,
7057    /// `is_dense`, `is_collapsed`, `filled`, and `align_label_with_hint` cannot be overridden.
7058    ///
7059    /// In other words, the fields of the provided `InputDecorationTheme` are used to
7060    /// fill in the unspecified and nullable fields of this InputDecorationTheme.
7061    pub fn merge(&self, other: Option<&InputDecorationTheme>) -> InputDecorationTheme {
7062        let Some(other) = other else {
7063            return self.clone();
7064        };
7065        let mut merged = self.copy_with();
7066        merged.label_style = self.label_style().or_else(|| other.label_style());
7067        merged.floating_label_style = self
7068            .floating_label_style()
7069            .or_else(|| other.floating_label_style());
7070        merged.helper_style = self.helper_style().or_else(|| other.helper_style());
7071        merged.helper_max_lines = self.helper_max_lines().or_else(|| other.helper_max_lines());
7072        merged.hint_style = self.hint_style().or_else(|| other.hint_style());
7073        merged.hint_fade_duration = self
7074            .hint_fade_duration()
7075            .or_else(|| other.hint_fade_duration());
7076        merged.hint_max_lines = self.hint_max_lines().or_else(|| other.hint_max_lines());
7077        merged.error_style = self.error_style().or_else(|| other.error_style());
7078        merged.error_max_lines = self.error_max_lines().or_else(|| other.error_max_lines());
7079        merged.content_padding = self.content_padding().or_else(|| other.content_padding());
7080        merged.icon_color = self.icon_color().or_else(|| other.icon_color());
7081        merged.prefix_style = self.prefix_style().or_else(|| other.prefix_style());
7082        merged.prefix_icon_color = self
7083            .prefix_icon_color()
7084            .or_else(|| other.prefix_icon_color());
7085        merged.prefix_icon_constraints = self
7086            .prefix_icon_constraints()
7087            .or_else(|| other.prefix_icon_constraints());
7088        merged.suffix_style = self.suffix_style().or_else(|| other.suffix_style());
7089        merged.suffix_icon_color = self
7090            .suffix_icon_color()
7091            .or_else(|| other.suffix_icon_color());
7092        merged.suffix_icon_constraints = self
7093            .suffix_icon_constraints()
7094            .or_else(|| other.suffix_icon_constraints());
7095        merged.counter_style = self.counter_style().or_else(|| other.counter_style());
7096        merged.fill_color = self.fill_color().or_else(|| other.fill_color());
7097        merged.active_indicator_border = self
7098            .active_indicator_border()
7099            .or_else(|| other.active_indicator_border());
7100        merged.outline_border = self.outline_border().or_else(|| other.outline_border());
7101        merged.focus_color = self.focus_color().or_else(|| other.focus_color());
7102        merged.hover_color = self.hover_color().or_else(|| other.hover_color());
7103        merged.error_border = self.error_border().or(other.error_border()).cloned();
7104        merged.focused_border = self.focused_border().or(other.focused_border()).cloned();
7105        merged.focused_error_border = self
7106            .focused_error_border()
7107            .or(other.focused_error_border())
7108            .cloned();
7109        merged.disabled_border = self.disabled_border().or(other.disabled_border()).cloned();
7110        merged.enabled_border = self.enabled_border().or(other.enabled_border()).cloned();
7111        merged.border = self.border().or(other.border()).cloned();
7112        merged.constraints = self.constraints().or_else(|| other.constraints());
7113        merged.visual_density = self.visual_density().or_else(|| other.visual_density());
7114        merged
7115    }
7116
7117    /// Dart's constructor assert: a `data` takes the place of every property.
7118    fn has_no_property(&self) -> bool {
7119        self.label_style.is_none()
7120            && self.floating_label_style.is_none()
7121            && self.helper_style.is_none()
7122            && self.helper_max_lines.is_none()
7123            && self.hint_style.is_none()
7124            && self.hint_fade_duration.is_none()
7125            && self.hint_max_lines.is_none()
7126            && self.error_style.is_none()
7127            && self.error_max_lines.is_none()
7128            && self.floating_label_behavior.is_none()
7129            && self.floating_label_alignment.is_none()
7130            && self.is_dense.is_none()
7131            && self.content_padding.is_none()
7132            && self.is_collapsed.is_none()
7133            && self.icon_color.is_none()
7134            && self.prefix_style.is_none()
7135            && self.prefix_icon_color.is_none()
7136            && self.prefix_icon_constraints.is_none()
7137            && self.suffix_style.is_none()
7138            && self.suffix_icon_color.is_none()
7139            && self.suffix_icon_constraints.is_none()
7140            && self.counter_style.is_none()
7141            && self.filled.is_none()
7142            && self.fill_color.is_none()
7143            && self.active_indicator_border.is_none()
7144            && self.outline_border.is_none()
7145            && self.focus_color.is_none()
7146            && self.hover_color.is_none()
7147            && self.error_border.is_none()
7148            && self.focused_border.is_none()
7149            && self.focused_error_border.is_none()
7150            && self.disabled_border.is_none()
7151            && self.enabled_border.is_none()
7152            && self.border.is_none()
7153            && self.align_label_with_hint.is_none()
7154            && self.constraints.is_none()
7155            && self.visual_density.is_none()
7156    }
7157}
7158
7159impl Default for InputDecorationTheme {
7160    fn default() -> InputDecorationTheme {
7161        InputDecorationTheme::new()
7162    }
7163}
7164
7165impl From<InputDecorationTheme> for InputDecorationThemeData {
7166    /// Dart's `inputDecorationTheme.data`, where an API takes either type.
7167    fn from(theme: InputDecorationTheme) -> InputDecorationThemeData {
7168        theme.data()
7169    }
7170}
7171
7172impl InheritedTheme for InputDecorationTheme {
7173    fn wrap(&self, _app: &mut App, _context: BuildContext, child: WidgetRef) -> WidgetRef {
7174        InputDecorationTheme::new()
7175            .with_data(self.data())
7176            .child(child)
7177            .into_widget()
7178    }
7179}
7180
7181impl InheritedWidget for InputDecorationTheme {
7182    fn key(&self) -> Option<&KeyRef> {
7183        self.key.as_ref()
7184    }
7185
7186    fn child(&self) -> &WidgetRef {
7187        &self.child
7188    }
7189
7190    fn update_should_notify(&self, old_widget: &InputDecorationTheme) -> bool {
7191        self.data() != old_widget.data()
7192    }
7193
7194    fn as_inherited_theme(&self) -> Option<&dyn InheritedTheme> {
7195        Some(self)
7196    }
7197}
7198
7199/// Defines the default appearance of `InputDecorator`s.
7200///
7201/// Descendant widgets obtain the current theme's `InputDecorationThemeData` using
7202/// `InputDecorationTheme::of`. When a widget uses `InputDecorationTheme::of`, it is
7203/// automatically rebuilt if the theme later changes.
7204///
7205/// The `InputDecoration::apply_defaults` method is used to combine an input
7206/// decoration theme with an `InputDecoration` object.
7207///
7208/// See also:
7209///
7210///  * `ThemeData::input_decoration_theme`, which specifies an input decoration theme as
7211///    part of the overall Material theme.
7212#[derive(Clone, PartialEq)]
7213pub struct InputDecorationThemeData {
7214    /// The style to use for `InputDecoration::label_text` when the label is on top
7215    /// of the input field.
7216    ///
7217    /// If `label_style` is a `WidgetStateTextStyle`, then the effective
7218    /// text style can depend on the `WidgetState::Focused` state, i.e.
7219    /// if the `TextField` is focused or not.
7220    ///
7221    /// When the `InputDecoration::label_text` is above (i.e., vertically adjacent to)
7222    /// the input field, the text uses the `floating_label_style` instead.
7223    ///
7224    /// If null, defaults to a value derived from the base `TextStyle` for the
7225    /// input field and the current `Theme`.
7226    ///
7227    /// Specifying this style will override the default behavior
7228    /// of `InputDecoration` that changes the color of the label to the
7229    /// `InputDecoration::error_style` color or `ColorScheme::error`.
7230    pub label_style: Option<AnyTextStyle>,
7231
7232    /// The style to use for `InputDecoration::label_text` when the label is
7233    /// above (i.e., vertically adjacent to) the input field.
7234    ///
7235    /// When the `InputDecoration::label_text` is on top of the input field, the
7236    /// text uses the `label_style` instead.
7237    ///
7238    /// If `floating_label_style` is a `WidgetStateTextStyle`, then the effective
7239    /// text style can depend on the `WidgetState::Focused` state, i.e.
7240    /// if the `TextField` is focused or not.
7241    ///
7242    /// If null, defaults to `label_style`.
7243    ///
7244    /// Specifying this style will override the default behavior
7245    /// of `InputDecoration` that changes the color of the label to the
7246    /// `InputDecoration::error_style` color or `ColorScheme::error`.
7247    ///
7248    /// When the input field receives focus, the font size of `InputDecoration::label` is
7249    /// scaled down by 75%.
7250    pub floating_label_style: Option<AnyTextStyle>,
7251
7252    /// The style to use for `InputDecoration::helper_text`.
7253    ///
7254    /// If `helper_style` is a `WidgetStateTextStyle`, then the effective
7255    /// text style can depend on the `WidgetState::Focused` state, i.e.
7256    /// if the `TextField` is focused or not.
7257    pub helper_style: Option<AnyTextStyle>,
7258
7259    /// The maximum number of lines the `InputDecoration::helper_text` can occupy.
7260    ///
7261    /// Defaults to null, which means that the `InputDecoration::helper_text` will
7262    /// be limited to a single line with `TextOverflow::Ellipsis`.
7263    ///
7264    /// This value is passed along to the `Text::max_lines` attribute
7265    /// of the `Text` widget used to display the helper.
7266    ///
7267    /// See also:
7268    ///
7269    ///  * `error_max_lines`, the equivalent but for the `InputDecoration::error_text`.
7270    pub helper_max_lines: Option<i32>,
7271
7272    /// The style to use for the `InputDecoration::hint_text`.
7273    ///
7274    /// If `hint_style` is a `WidgetStateTextStyle`, then the effective
7275    /// text style can depend on the `WidgetState::Focused` state, i.e.
7276    /// if the `TextField` is focused or not.
7277    ///
7278    /// Also used for the `InputDecoration::label_text` when the
7279    /// `InputDecoration::label_text` is displayed on top of the input field (i.e.,
7280    /// at the same location on the screen where text may be entered in the input
7281    /// field).
7282    ///
7283    /// If null, defaults to a value derived from the base `TextStyle` for the
7284    /// input field and the current `Theme`.
7285    pub hint_style: Option<AnyTextStyle>,
7286
7287    /// The duration of the `InputDecoration::hint_text` fade in and fade out animations.
7288    pub hint_fade_duration: Option<Duration>,
7289
7290    /// The maximum number of lines the `InputDecoration::hint_text` can occupy.
7291    ///
7292    /// Defaults to null, which means that the `InputDecoration::hint_text` will
7293    /// be limited to a single line with `TextOverflow::Ellipsis`.
7294    ///
7295    /// This value is passed along to the `Text::max_lines` attribute
7296    /// of the `Text` widget used to display the hint text.
7297    pub hint_max_lines: Option<i32>,
7298
7299    /// The style to use for the `InputDecoration::error_text`.
7300    ///
7301    /// If null, defaults of a value derived from the base `TextStyle` for the
7302    /// input field and the current `Theme`.
7303    ///
7304    /// By default the color of style will be used by the label of
7305    /// `InputDecoration` if `InputDecoration::error_text` is not null. See
7306    /// `InputDecoration::label_style` or `InputDecoration::floating_label_style` for
7307    /// an example of how to replicate this behavior when specifying those
7308    /// styles.
7309    pub error_style: Option<AnyTextStyle>,
7310
7311    /// The maximum number of lines the `InputDecoration::error_text` can occupy.
7312    ///
7313    /// Defaults to null, which means that the `InputDecoration::error_text` will be
7314    /// limited to a single line with `TextOverflow::Ellipsis`.
7315    ///
7316    /// This value is passed along to the `Text::max_lines` attribute
7317    /// of the `Text` widget used to display the error.
7318    ///
7319    /// See also:
7320    ///
7321    ///  * `helper_max_lines`, the equivalent but for the `InputDecoration::helper_text`.
7322    pub error_max_lines: Option<i32>,
7323
7324    /// Defines **how** the floating label should behave.
7325    ///
7326    /// When `FloatingLabelBehavior::Auto` the label will float to the top only when
7327    /// the field is focused or has some text content, otherwise it will appear
7328    /// in the field in place of the content.
7329    ///
7330    /// When `FloatingLabelBehavior::Always` the label will always float at the top
7331    /// of the field above the content.
7332    ///
7333    /// When `FloatingLabelBehavior::Never` the label will always appear in an empty
7334    /// field in place of the content.
7335    ///
7336    /// Defaults to `FloatingLabelBehavior::Auto`.
7337    pub floating_label_behavior: FloatingLabelBehavior,
7338
7339    /// Defines **where** the floating label should be displayed.
7340    ///
7341    /// `FloatingLabelAlignment::START` aligns the floating label to the leftmost
7342    /// (when `TextDirection::Ltr`) or rightmost (when `TextDirection::Rtl`),
7343    /// possible position, which is vertically adjacent to the label, on top of
7344    /// the field.
7345    ///
7346    /// `FloatingLabelAlignment::CENTER` aligns the floating label to the center on
7347    /// top of the field.
7348    ///
7349    /// Defaults to `FloatingLabelAlignment::START`.
7350    pub floating_label_alignment: FloatingLabelAlignment,
7351
7352    /// Whether the input decorator's child is part of a dense form (i.e., uses
7353    /// less vertical space).
7354    ///
7355    /// Defaults to false.
7356    pub is_dense: bool,
7357
7358    /// The padding for the input decoration's container.
7359    ///
7360    /// The decoration's container is the area which is filled if
7361    /// `InputDecoration::filled` is true and bordered per the `border`.
7362    /// It's the area adjacent to `InputDecoration::icon` and above the
7363    /// `InputDecoration::icon` and above the widgets that contain
7364    /// `InputDecoration::helper_text`, `InputDecoration::error_text`, and
7365    /// `InputDecoration::counter_text`.
7366    ///
7367    /// By default the `content_padding` reflects `visual_density`, `is_dense` and
7368    /// the type of the `border`. If `is_collapsed` is true then `content_padding`
7369    /// is `EdgeInsets::ZERO`.
7370    pub content_padding: Option<EdgeInsetsGeometry>,
7371
7372    /// Whether the decoration is the same size as the input field.
7373    ///
7374    /// A collapsed decoration cannot have `InputDecoration::label_text`,
7375    /// `InputDecoration::error_text`, or an `InputDecoration::icon`.
7376    pub is_collapsed: bool,
7377
7378    /// The Color to use for the `InputDecoration::icon`.
7379    ///
7380    /// If `icon_color` is a `WidgetStateColor`, then the effective
7381    /// color can depend on the `WidgetState::Focused` state, i.e.
7382    /// if the `TextField` is focused or not.
7383    ///
7384    /// If null, defaults to the `ColorScheme::primary`.
7385    pub icon_color: Option<AnyColor>,
7386
7387    /// The style to use for the `InputDecoration::prefix_text`.
7388    ///
7389    /// If `prefix_style` is a `WidgetStateTextStyle`, then the effective
7390    /// text style can depend on the `WidgetState::Focused` state, i.e.
7391    /// if the `TextField` is focused or not.
7392    ///
7393    /// If null, defaults to the `hint_style`.
7394    pub prefix_style: Option<AnyTextStyle>,
7395
7396    /// The Color to use for the `InputDecoration::prefix_icon`.
7397    ///
7398    /// If `prefix_icon_color` is a `WidgetStateColor`, then the effective
7399    /// color can depend on the `WidgetState::Focused` state, i.e.
7400    /// if the `TextField` is focused or not.
7401    ///
7402    /// If null, defaults to the `ColorScheme::primary`.
7403    pub prefix_icon_color: Option<AnyColor>,
7404
7405    /// The constraints to use for `InputDecoration::prefix_icon_constraints`.
7406    ///
7407    /// This can be used to modify the `BoxConstraints` surrounding
7408    /// `InputDecoration::prefix_icon`.
7409    ///
7410    /// This property is particularly useful for getting the decoration's height
7411    /// less than the minimum tappable height (which is 48px when the visual
7412    /// density is set to `VisualDensity::standard`). This can be achieved by
7413    /// setting `is_dense` to true and setting the constraints' minimum height
7414    /// and width to a value lower than the minimum tappable size.
7415    ///
7416    /// If null, `BoxConstraints` with a minimum width and height of 48px is
7417    /// used.
7418    pub prefix_icon_constraints: Option<BoxConstraints>,
7419
7420    /// The style to use for the `InputDecoration::suffix_text`.
7421    ///
7422    /// If `suffix_style` is a `WidgetStateTextStyle`, then the effective
7423    /// color can depend on the `WidgetState::Focused` state, i.e.
7424    /// if the `TextField` is focused or not.
7425    ///
7426    /// If null, defaults to the `hint_style`.
7427    pub suffix_style: Option<AnyTextStyle>,
7428
7429    /// The Color to use for the `InputDecoration::suffix_icon`.
7430    ///
7431    /// If `suffix_icon_color` is a `WidgetStateColor`, then the effective
7432    /// color can depend on the `WidgetState::Focused` state, i.e.
7433    /// if the `TextField` is focused or not.
7434    ///
7435    /// If null, defaults to the `ColorScheme::primary`.
7436    pub suffix_icon_color: Option<AnyColor>,
7437
7438    /// The constraints to use for `InputDecoration::suffix_icon_constraints`.
7439    ///
7440    /// This can be used to modify the `BoxConstraints` surrounding
7441    /// `InputDecoration::suffix_icon`.
7442    ///
7443    /// This property is particularly useful for getting the decoration's height
7444    /// less than the minimum tappable height (which is 48px when the visual
7445    /// density is set to `VisualDensity::standard`). This can be achieved by
7446    /// setting `is_dense` to true and setting the constraints' minimum height
7447    /// and width to a value lower than the minimum tappable size.
7448    ///
7449    /// If null, `BoxConstraints` with a minimum width and height of 48px is
7450    /// used.
7451    pub suffix_icon_constraints: Option<BoxConstraints>,
7452
7453    /// The style to use for the `InputDecoration::counter_text`.
7454    ///
7455    /// If `counter_style` is a `WidgetStateTextStyle`, then the effective
7456    /// text style can depend on the `WidgetState::Focused` state, i.e.
7457    /// if the `TextField` is focused or not.
7458    ///
7459    /// If null, defaults to the `helper_style`.
7460    pub counter_style: Option<AnyTextStyle>,
7461
7462    /// If true the decoration's container is filled with `fill_color`.
7463    ///
7464    /// Typically this field set to true if `border` is an
7465    /// `UnderlineInputBorder`.
7466    ///
7467    /// The decoration's container is the area, defined by the border's
7468    /// `InputBorder::get_outer_path`, which is filled if `filled` is
7469    /// true and bordered per the `border`.
7470    ///
7471    /// This property is false by default.
7472    pub filled: bool,
7473
7474    /// The color to fill the decoration's container with, if `filled` is true.
7475    ///
7476    /// By default the fillColor is based on the current `Theme`.
7477    ///
7478    /// The decoration's container is the area, defined by the border's
7479    /// `InputBorder::get_outer_path`, which is filled if `filled` is
7480    /// true and bordered per the `border`.
7481    pub fill_color: Option<AnyColor>,
7482
7483    /// The borderSide of the OutlineInputBorder with `color` and `weight`.
7484    pub outline_border: Option<AnyBorderSide>,
7485
7486    /// The borderSide of the UnderlineInputBorder with `color` and `weight`.
7487    pub active_indicator_border: Option<AnyBorderSide>,
7488
7489    /// The color to blend with the decoration's `fill_color` with, if `filled` is
7490    /// true and the container has the input focus.
7491    ///
7492    /// By default the `focus_color` is based on the current `Theme`.
7493    ///
7494    /// The decoration's container is the area, defined by the border's
7495    /// `InputBorder::get_outer_path`, which is filled if `filled` is
7496    /// true and bordered per the `border`.
7497    pub focus_color: Option<Color>,
7498
7499    /// The color to blend with the decoration's `fill_color` with, if the
7500    /// decoration is being hovered over by a mouse pointer.
7501    ///
7502    /// By default the `hover_color` is based on the current `Theme`.
7503    ///
7504    /// The decoration's container is the area, defined by the border's
7505    /// `InputBorder::get_outer_path`, which is filled if `filled` is
7506    /// true and bordered per the `border`.
7507    ///
7508    /// The container will be filled when hovered over even if `filled` is false.
7509    pub hover_color: Option<Color>,
7510
7511    /// The border to display when the `InputDecorator` does not have the focus and
7512    /// is showing an error.
7513    ///
7514    /// See also:
7515    ///
7516    ///  * `InputDecorator::is_focused`, which is true if the `InputDecorator`'s child
7517    ///    has the focus.
7518    ///  * `InputDecoration::error_text`, the error shown by the `InputDecorator`, if non-null.
7519    ///  * `border`, for a description of where the `InputDecorator` border appears.
7520    ///  * `UnderlineInputBorder`, an `InputDecorator` border which draws a horizontal
7521    ///    line at the bottom of the input decorator's container.
7522    ///  * `OutlineInputBorder`, an `InputDecorator` border which draws a
7523    ///    rounded rectangle around the input decorator's container.
7524    ///  * `InputBorderRef::none()`, which doesn't draw a border.
7525    ///  * `focused_border`, displayed when `InputDecorator::is_focused` is true
7526    ///    and `InputDecoration::error_text` is null.
7527    ///  * `focused_error_border`, displayed when `InputDecorator::is_focused` is true
7528    ///    and `InputDecoration::error_text` is non-null.
7529    ///  * `disabled_border`, displayed when `InputDecoration::enabled` is false
7530    ///    and `InputDecoration::error_text` is null.
7531    ///  * `enabled_border`, displayed when `InputDecoration::enabled` is true
7532    ///    and `InputDecoration::error_text` is null.
7533    pub error_border: Option<InputBorderRef>,
7534
7535    /// The border to display when the `InputDecorator` has the focus and is not
7536    /// showing an error.
7537    ///
7538    /// See also:
7539    ///
7540    ///  * `InputDecorator::is_focused`, which is true if the `InputDecorator`'s child
7541    ///    has the focus.
7542    ///  * `InputDecoration::error_text`, the error shown by the `InputDecorator`, if non-null.
7543    ///  * `border`, for a description of where the `InputDecorator` border appears.
7544    ///  * `UnderlineInputBorder`, an `InputDecorator` border which draws a horizontal
7545    ///    line at the bottom of the input decorator's container.
7546    ///  * `OutlineInputBorder`, an `InputDecorator` border which draws a
7547    ///    rounded rectangle around the input decorator's container.
7548    ///  * `InputBorderRef::none()`, which doesn't draw a border.
7549    ///  * `error_border`, displayed when `InputDecorator::is_focused` is false
7550    ///    and `InputDecoration::error_text` is non-null.
7551    ///  * `focused_error_border`, displayed when `InputDecorator::is_focused` is true
7552    ///    and `InputDecoration::error_text` is non-null.
7553    ///  * `disabled_border`, displayed when `InputDecoration::enabled` is false
7554    ///    and `InputDecoration::error_text` is null.
7555    ///  * `enabled_border`, displayed when `InputDecoration::enabled` is true
7556    ///    and `InputDecoration::error_text` is null.
7557    pub focused_border: Option<InputBorderRef>,
7558
7559    /// The border to display when the `InputDecorator` has the focus and is
7560    /// showing an error.
7561    ///
7562    /// See also:
7563    ///
7564    ///  * `InputDecorator::is_focused`, which is true if the `InputDecorator`'s child
7565    ///    has the focus.
7566    ///  * `InputDecoration::error_text`, the error shown by the `InputDecorator`, if non-null.
7567    ///  * `border`, for a description of where the `InputDecorator` border appears.
7568    ///  * `UnderlineInputBorder`, an `InputDecorator` border which draws a horizontal
7569    ///    line at the bottom of the input decorator's container.
7570    ///  * `OutlineInputBorder`, an `InputDecorator` border which draws a
7571    ///    rounded rectangle around the input decorator's container.
7572    ///  * `InputBorderRef::none()`, which doesn't draw a border.
7573    ///  * `error_border`, displayed when `InputDecorator::is_focused` is false
7574    ///    and `InputDecoration::error_text` is non-null.
7575    ///  * `focused_border`, displayed when `InputDecorator::is_focused` is true
7576    ///    and `InputDecoration::error_text` is null.
7577    ///  * `disabled_border`, displayed when `InputDecoration::enabled` is false
7578    ///    and `InputDecoration::error_text` is null.
7579    ///  * `enabled_border`, displayed when `InputDecoration::enabled` is true
7580    ///    and `InputDecoration::error_text` is null.
7581    pub focused_error_border: Option<InputBorderRef>,
7582
7583    /// The border to display when the `InputDecorator` is disabled and is not
7584    /// showing an error.
7585    ///
7586    /// See also:
7587    ///
7588    ///  * `InputDecoration::enabled`, which is false if the `InputDecorator` is disabled.
7589    ///  * `InputDecoration::error_text`, the error shown by the `InputDecorator`, if non-null.
7590    ///  * `border`, for a description of where the `InputDecorator` border appears.
7591    ///  * `UnderlineInputBorder`, an `InputDecorator` border which draws a horizontal
7592    ///    line at the bottom of the input decorator's container.
7593    ///  * `OutlineInputBorder`, an `InputDecorator` border which draws a
7594    ///    rounded rectangle around the input decorator's container.
7595    ///  * `InputBorderRef::none()`, which doesn't draw a border.
7596    ///  * `error_border`, displayed when `InputDecorator::is_focused` is false
7597    ///    and `InputDecoration::error_text` is non-null.
7598    ///  * `focused_border`, displayed when `InputDecorator::is_focused` is true
7599    ///    and `InputDecoration::error_text` is null.
7600    ///  * `focused_error_border`, displayed when `InputDecorator::is_focused` is true
7601    ///    and `InputDecoration::error_text` is non-null.
7602    ///  * `enabled_border`, displayed when `InputDecoration::enabled` is true
7603    ///    and `InputDecoration::error_text` is null.
7604    pub disabled_border: Option<InputBorderRef>,
7605
7606    /// The border to display when the `InputDecorator` is enabled and is not
7607    /// showing an error.
7608    ///
7609    /// See also:
7610    ///
7611    ///  * `InputDecoration::enabled`, which is false if the `InputDecorator` is disabled.
7612    ///  * `InputDecoration::error_text`, the error shown by the `InputDecorator`, if non-null.
7613    ///  * `border`, for a description of where the `InputDecorator` border appears.
7614    ///  * `UnderlineInputBorder`, an `InputDecorator` border which draws a horizontal
7615    ///    line at the bottom of the input decorator's container.
7616    ///  * `OutlineInputBorder`, an `InputDecorator` border which draws a
7617    ///    rounded rectangle around the input decorator's container.
7618    ///  * `InputBorderRef::none()`, which doesn't draw a border.
7619    ///  * `error_border`, displayed when `InputDecorator::is_focused` is false
7620    ///    and `InputDecoration::error_text` is non-null.
7621    ///  * `focused_border`, displayed when `InputDecorator::is_focused` is true
7622    ///    and `InputDecoration::error_text` is null.
7623    ///  * `focused_error_border`, displayed when `InputDecorator::is_focused` is true
7624    ///    and `InputDecoration::error_text` is non-null.
7625    ///  * `disabled_border`, displayed when `InputDecoration::enabled` is false
7626    ///    and `InputDecoration::error_text` is null.
7627    pub enabled_border: Option<InputBorderRef>,
7628
7629    /// The shape of the border to draw around the decoration's container.
7630    ///
7631    /// If `border` is a `WidgetStateInputBorder`, then the effective border can
7632    /// depend on the `WidgetState::Focused` state, i.e. if the `TextField` is
7633    /// focused or not.
7634    ///
7635    /// The decoration's container is the area which is filled if `filled` is
7636    /// true and bordered per the `border`. It's the area adjacent to
7637    /// `InputDecoration::icon` and above the widgets that contain
7638    /// `InputDecoration::helper_text`, `InputDecoration::error_text`, and
7639    /// `InputDecoration::counter_text`.
7640    ///
7641    /// The border's bounds, i.e. the value of `border.getOuterPath()`, define
7642    /// the area to be filled.
7643    ///
7644    /// This property is only used when the appropriate one of `error_border`,
7645    /// `focused_border`, `focused_error_border`, `disabled_border`, or `enabled_border`
7646    /// is not specified. This border's `InputBorder::border_side` property is
7647    /// configured by the InputDecorator, depending on the values of
7648    /// `InputDecoration::error_text`, `InputDecoration::enabled`,
7649    /// `InputDecorator::is_focused` and the current `Theme`.
7650    ///
7651    /// Typically one of `UnderlineInputBorder` or `OutlineInputBorder`.
7652    /// If null, InputDecorator's default is `const UnderlineInputBorder()`.
7653    ///
7654    /// See also:
7655    ///
7656    ///  * `InputBorderRef::none()`, which doesn't draw a border.
7657    ///  * `UnderlineInputBorder`, which draws a horizontal line at the
7658    ///    bottom of the input decorator's container.
7659    ///  * `OutlineInputBorder`, an `InputDecorator` border which draws a
7660    ///    rounded rectangle around the input decorator's container.
7661    pub border: Option<InputBorderRef>,
7662
7663    /// Typically set to true when the `InputDecorator` contains a multiline
7664    /// `TextField` (`TextField::max_lines` is null or > 1) to override the default
7665    /// behavior of aligning the label with the center of the `TextField`.
7666    pub align_label_with_hint: bool,
7667
7668    /// Defines minimum and maximum sizes for the `InputDecorator`.
7669    ///
7670    /// Typically the decorator will fill the horizontal space it is given. For
7671    /// larger screens, it may be useful to have the maximum width clamped to
7672    /// a given value so it doesn't fill the whole screen. This property
7673    /// allows you to control how big the decorator will be in its available
7674    /// space.
7675    ///
7676    /// If null, then the decorator will fill the available width with
7677    /// a default height based on text size.
7678    ///
7679    /// See also:
7680    ///
7681    ///  * `InputDecoration::constraints`, which can override this setting for a
7682    ///    given decorator.
7683    pub constraints: Option<BoxConstraints>,
7684
7685    /// Defines how compact the decoration's layout will be.
7686    ///
7687    /// The vertical aspect of the default or user-specified `content_padding` is adjusted
7688    /// automatically based on `visual_density`.
7689    ///
7690    /// When the visual density is `VisualDensity::compact`, the vertical aspect of
7691    /// `content_padding` is reduced by 8 pixels.
7692    ///
7693    /// When the visual density is `VisualDensity::comfortable`, the vertical aspect of
7694    /// `content_padding` is reduced by 4 pixels.
7695    ///
7696    /// When the visual density is `VisualDensity::standard` vertical aspect of
7697    /// `content_padding` is not changed.
7698    ///
7699    /// If null, defaults to `ThemeData::visual_density`.
7700    ///
7701    /// See also:
7702    ///
7703    ///  * `ThemeData::visual_density`, which specifies the `visual_density` for all widgets
7704    ///    within a `Theme`.
7705    ///  * `InputDecoration::visual_density`, which can override this setting for a
7706    ///    given decorator.
7707    pub visual_density: Option<VisualDensity>,
7708
7709    /// The padding around the supporting text row, which contains the helper
7710    /// text, the error text, and the counter.
7711    ///
7712    /// The start and end values set the horizontal position of the row, the
7713    /// same way `InputDecoration::content_padding` does for the input. The top
7714    /// value is the gap between the bottom of the decoration's container and
7715    /// the row, and the bottom value is the space below the row.
7716    ///
7717    /// If null, the row uses these defaults:
7718    ///
7719    ///  * start and end: the start and end values of
7720    ///    `InputDecoration::content_padding`.
7721    ///  * top: 4.0 for Material 3, 8.0 for Material 2.
7722    ///  * bottom: 0.0.
7723    ///
7724    /// If non-null, every side of this value is used as is, including sides
7725    /// that are zero. For example, `EdgeInsetsDirectional.only(start: 24.0)`
7726    /// sets the top gap to zero, so the supporting text sits directly against
7727    /// the container. To change the horizontal padding while keeping the
7728    /// default Material 3 gap, set the top value explicitly:
7729    ///
7730    /// ```text
7731    /// const InputDecoration(
7732    ///   helperText: 'Helper text',
7733    ///   supportingTextPadding: EdgeInsetsDirectional.fromSTEB(24.0, 4.0, 24.0, 0.0),
7734    /// )
7735    /// ```
7736    pub supporting_text_padding: Option<EdgeInsetsGeometry>,
7737}
7738
7739crate::theme_data_getters::theme_data_getters! {
7740    /// Dart's getters of `InputDecorationThemeData`: the theme data answers with its fields, and a defaults
7741    /// subclass (Dart's `_...Defaults...(context)`) computes the ones it overrides when they
7742    /// are read.
7743    pub trait InputDecorationThemeDataGetters for InputDecorationThemeData, fields: input_decoration_theme_data {
7744        label_style: Option<AnyTextStyle>,
7745        floating_label_style: Option<AnyTextStyle>,
7746        helper_style: Option<AnyTextStyle>,
7747        helper_max_lines: Option<i32>,
7748        hint_style: Option<AnyTextStyle>,
7749        hint_fade_duration: Option<Duration>,
7750        hint_max_lines: Option<i32>,
7751        error_style: Option<AnyTextStyle>,
7752        error_max_lines: Option<i32>,
7753        floating_label_behavior: FloatingLabelBehavior,
7754        floating_label_alignment: FloatingLabelAlignment,
7755        is_dense: bool,
7756        content_padding: Option<EdgeInsetsGeometry>,
7757        is_collapsed: bool,
7758        icon_color: Option<AnyColor>,
7759        prefix_style: Option<AnyTextStyle>,
7760        prefix_icon_color: Option<AnyColor>,
7761        prefix_icon_constraints: Option<BoxConstraints>,
7762        suffix_style: Option<AnyTextStyle>,
7763        suffix_icon_color: Option<AnyColor>,
7764        suffix_icon_constraints: Option<BoxConstraints>,
7765        counter_style: Option<AnyTextStyle>,
7766        filled: bool,
7767        fill_color: Option<AnyColor>,
7768        outline_border: Option<AnyBorderSide>,
7769        active_indicator_border: Option<AnyBorderSide>,
7770        focus_color: Option<Color>,
7771        hover_color: Option<Color>,
7772        error_border: Option<InputBorderRef>,
7773        focused_border: Option<InputBorderRef>,
7774        focused_error_border: Option<InputBorderRef>,
7775        disabled_border: Option<InputBorderRef>,
7776        enabled_border: Option<InputBorderRef>,
7777        border: Option<InputBorderRef>,
7778        align_label_with_hint: bool,
7779        constraints: Option<BoxConstraints>,
7780        visual_density: Option<VisualDensity>,
7781        supporting_text_padding: Option<EdgeInsetsGeometry>,
7782    }
7783}
7784
7785impl InputDecorationThemeData {
7786    /// Creates a `InputDecorationThemeData` that can be used to override default
7787    /// properties in a `InputDecorationTheme` widget.
7788    pub fn new() -> InputDecorationThemeData {
7789        InputDecorationThemeData {
7790            label_style: None,
7791            floating_label_style: None,
7792            helper_style: None,
7793            helper_max_lines: None,
7794            hint_style: None,
7795            hint_fade_duration: None,
7796            hint_max_lines: None,
7797            error_style: None,
7798            error_max_lines: None,
7799            floating_label_behavior: FloatingLabelBehavior::Auto,
7800            floating_label_alignment: FloatingLabelAlignment::START,
7801            is_dense: false,
7802            content_padding: None,
7803            is_collapsed: false,
7804            icon_color: None,
7805            prefix_style: None,
7806            prefix_icon_color: None,
7807            prefix_icon_constraints: None,
7808            suffix_style: None,
7809            suffix_icon_color: None,
7810            suffix_icon_constraints: None,
7811            counter_style: None,
7812            filled: false,
7813            fill_color: None,
7814            outline_border: None,
7815            active_indicator_border: None,
7816            focus_color: None,
7817            hover_color: None,
7818            error_border: None,
7819            focused_border: None,
7820            focused_error_border: None,
7821            disabled_border: None,
7822            enabled_border: None,
7823            border: None,
7824            align_label_with_hint: false,
7825            constraints: None,
7826            visual_density: None,
7827            supporting_text_padding: None,
7828        }
7829    }
7830
7831    /// Dart `InputDecorationThemeData(labelStyle:)`.
7832    pub fn label_style(mut self, label_style: impl Into<AnyTextStyle>) -> InputDecorationThemeData {
7833        self.label_style = Some(label_style.into());
7834        self
7835    }
7836
7837    /// Dart `InputDecorationThemeData(floatingLabelStyle:)`.
7838    pub fn floating_label_style(
7839        mut self,
7840        floating_label_style: impl Into<AnyTextStyle>,
7841    ) -> InputDecorationThemeData {
7842        self.floating_label_style = Some(floating_label_style.into());
7843        self
7844    }
7845
7846    /// Dart `InputDecorationThemeData(helperStyle:)`.
7847    pub fn helper_style(
7848        mut self,
7849        helper_style: impl Into<AnyTextStyle>,
7850    ) -> InputDecorationThemeData {
7851        self.helper_style = Some(helper_style.into());
7852        self
7853    }
7854
7855    /// Dart `InputDecorationThemeData(helperMaxLines:)`.
7856    pub fn helper_max_lines(mut self, helper_max_lines: i32) -> InputDecorationThemeData {
7857        self.helper_max_lines = Some(helper_max_lines);
7858        self
7859    }
7860
7861    /// Dart `InputDecorationThemeData(hintStyle:)`.
7862    pub fn hint_style(mut self, hint_style: impl Into<AnyTextStyle>) -> InputDecorationThemeData {
7863        self.hint_style = Some(hint_style.into());
7864        self
7865    }
7866
7867    /// Dart `InputDecorationThemeData(hintFadeDuration:)`.
7868    pub fn hint_fade_duration(mut self, hint_fade_duration: Duration) -> InputDecorationThemeData {
7869        self.hint_fade_duration = Some(hint_fade_duration);
7870        self
7871    }
7872
7873    /// Dart `InputDecorationThemeData(hintMaxLines:)`.
7874    pub fn hint_max_lines(mut self, hint_max_lines: i32) -> InputDecorationThemeData {
7875        self.hint_max_lines = Some(hint_max_lines);
7876        self
7877    }
7878
7879    /// Dart `InputDecorationThemeData(errorStyle:)`.
7880    pub fn error_style(mut self, error_style: impl Into<AnyTextStyle>) -> InputDecorationThemeData {
7881        self.error_style = Some(error_style.into());
7882        self
7883    }
7884
7885    /// Dart `InputDecorationThemeData(errorMaxLines:)`.
7886    pub fn error_max_lines(mut self, error_max_lines: i32) -> InputDecorationThemeData {
7887        self.error_max_lines = Some(error_max_lines);
7888        self
7889    }
7890
7891    /// Dart `InputDecorationThemeData(floatingLabelBehavior:)`.
7892    pub fn floating_label_behavior(
7893        mut self,
7894        floating_label_behavior: FloatingLabelBehavior,
7895    ) -> InputDecorationThemeData {
7896        self.floating_label_behavior = floating_label_behavior;
7897        self
7898    }
7899
7900    /// Dart `InputDecorationThemeData(floatingLabelAlignment:)`.
7901    pub fn floating_label_alignment(
7902        mut self,
7903        floating_label_alignment: FloatingLabelAlignment,
7904    ) -> InputDecorationThemeData {
7905        self.floating_label_alignment = floating_label_alignment;
7906        self
7907    }
7908
7909    /// Dart `InputDecorationThemeData(isDense:)`.
7910    pub fn is_dense(mut self, is_dense: bool) -> InputDecorationThemeData {
7911        self.is_dense = is_dense;
7912        self
7913    }
7914
7915    /// Dart `InputDecorationThemeData(contentPadding:)`.
7916    pub fn content_padding(
7917        mut self,
7918        content_padding: impl Into<EdgeInsetsGeometry>,
7919    ) -> InputDecorationThemeData {
7920        let content_padding = content_padding.into();
7921        self.content_padding = Some(content_padding);
7922        self
7923    }
7924
7925    /// Dart `InputDecorationThemeData(isCollapsed:)`.
7926    pub fn is_collapsed(mut self, is_collapsed: bool) -> InputDecorationThemeData {
7927        self.is_collapsed = is_collapsed;
7928        self
7929    }
7930
7931    /// Dart `InputDecorationThemeData(iconColor:)`.
7932    pub fn icon_color(mut self, icon_color: impl Into<AnyColor>) -> InputDecorationThemeData {
7933        self.icon_color = Some(icon_color.into());
7934        self
7935    }
7936
7937    /// Dart `InputDecorationThemeData(prefixStyle:)`.
7938    pub fn prefix_style(
7939        mut self,
7940        prefix_style: impl Into<AnyTextStyle>,
7941    ) -> InputDecorationThemeData {
7942        self.prefix_style = Some(prefix_style.into());
7943        self
7944    }
7945
7946    /// Dart `InputDecorationThemeData(prefixIconColor:)`.
7947    pub fn prefix_icon_color(
7948        mut self,
7949        prefix_icon_color: impl Into<AnyColor>,
7950    ) -> InputDecorationThemeData {
7951        self.prefix_icon_color = Some(prefix_icon_color.into());
7952        self
7953    }
7954
7955    /// Dart `InputDecorationThemeData(prefixIconConstraints:)`.
7956    pub fn prefix_icon_constraints(
7957        mut self,
7958        prefix_icon_constraints: BoxConstraints,
7959    ) -> InputDecorationThemeData {
7960        self.prefix_icon_constraints = Some(prefix_icon_constraints);
7961        self
7962    }
7963
7964    /// Dart `InputDecorationThemeData(suffixStyle:)`.
7965    pub fn suffix_style(
7966        mut self,
7967        suffix_style: impl Into<AnyTextStyle>,
7968    ) -> InputDecorationThemeData {
7969        self.suffix_style = Some(suffix_style.into());
7970        self
7971    }
7972
7973    /// Dart `InputDecorationThemeData(suffixIconColor:)`.
7974    pub fn suffix_icon_color(
7975        mut self,
7976        suffix_icon_color: impl Into<AnyColor>,
7977    ) -> InputDecorationThemeData {
7978        self.suffix_icon_color = Some(suffix_icon_color.into());
7979        self
7980    }
7981
7982    /// Dart `InputDecorationThemeData(suffixIconConstraints:)`.
7983    pub fn suffix_icon_constraints(
7984        mut self,
7985        suffix_icon_constraints: BoxConstraints,
7986    ) -> InputDecorationThemeData {
7987        self.suffix_icon_constraints = Some(suffix_icon_constraints);
7988        self
7989    }
7990
7991    /// Dart `InputDecorationThemeData(counterStyle:)`.
7992    pub fn counter_style(
7993        mut self,
7994        counter_style: impl Into<AnyTextStyle>,
7995    ) -> InputDecorationThemeData {
7996        self.counter_style = Some(counter_style.into());
7997        self
7998    }
7999
8000    /// Dart `InputDecorationThemeData(filled:)`.
8001    pub fn filled(mut self, filled: bool) -> InputDecorationThemeData {
8002        self.filled = filled;
8003        self
8004    }
8005
8006    /// Dart `InputDecorationThemeData(fillColor:)`.
8007    pub fn fill_color(mut self, fill_color: impl Into<AnyColor>) -> InputDecorationThemeData {
8008        self.fill_color = Some(fill_color.into());
8009        self
8010    }
8011
8012    /// Dart `InputDecorationThemeData(activeIndicatorBorder:)`.
8013    pub fn active_indicator_border(
8014        mut self,
8015        active_indicator_border: impl Into<AnyBorderSide>,
8016    ) -> InputDecorationThemeData {
8017        self.active_indicator_border = Some(active_indicator_border.into());
8018        self
8019    }
8020
8021    /// Dart `InputDecorationThemeData(outlineBorder:)`.
8022    pub fn outline_border(
8023        mut self,
8024        outline_border: impl Into<AnyBorderSide>,
8025    ) -> InputDecorationThemeData {
8026        self.outline_border = Some(outline_border.into());
8027        self
8028    }
8029
8030    /// Dart `InputDecorationThemeData(focusColor:)`.
8031    pub fn focus_color(mut self, focus_color: Color) -> InputDecorationThemeData {
8032        self.focus_color = Some(focus_color);
8033        self
8034    }
8035
8036    /// Dart `InputDecorationThemeData(hoverColor:)`.
8037    pub fn hover_color(mut self, hover_color: Color) -> InputDecorationThemeData {
8038        self.hover_color = Some(hover_color);
8039        self
8040    }
8041
8042    /// Dart `InputDecorationThemeData(errorBorder:)`.
8043    pub fn error_border(
8044        mut self,
8045        error_border: impl Into<InputBorderRef>,
8046    ) -> InputDecorationThemeData {
8047        self.error_border = Some(error_border.into());
8048        self
8049    }
8050
8051    /// Dart `InputDecorationThemeData(focusedBorder:)`.
8052    pub fn focused_border(
8053        mut self,
8054        focused_border: impl Into<InputBorderRef>,
8055    ) -> InputDecorationThemeData {
8056        self.focused_border = Some(focused_border.into());
8057        self
8058    }
8059
8060    /// Dart `InputDecorationThemeData(focusedErrorBorder:)`.
8061    pub fn focused_error_border(
8062        mut self,
8063        focused_error_border: impl Into<InputBorderRef>,
8064    ) -> InputDecorationThemeData {
8065        self.focused_error_border = Some(focused_error_border.into());
8066        self
8067    }
8068
8069    /// Dart `InputDecorationThemeData(disabledBorder:)`.
8070    pub fn disabled_border(
8071        mut self,
8072        disabled_border: impl Into<InputBorderRef>,
8073    ) -> InputDecorationThemeData {
8074        self.disabled_border = Some(disabled_border.into());
8075        self
8076    }
8077
8078    /// Dart `InputDecorationThemeData(enabledBorder:)`.
8079    pub fn enabled_border(
8080        mut self,
8081        enabled_border: impl Into<InputBorderRef>,
8082    ) -> InputDecorationThemeData {
8083        self.enabled_border = Some(enabled_border.into());
8084        self
8085    }
8086
8087    /// Dart `InputDecorationThemeData(border:)`.
8088    pub fn border(mut self, border: impl Into<InputBorderRef>) -> InputDecorationThemeData {
8089        self.border = Some(border.into());
8090        self
8091    }
8092
8093    /// Dart `InputDecorationThemeData(alignLabelWithHint:)`.
8094    pub fn align_label_with_hint(
8095        mut self,
8096        align_label_with_hint: bool,
8097    ) -> InputDecorationThemeData {
8098        self.align_label_with_hint = align_label_with_hint;
8099        self
8100    }
8101
8102    /// Dart `InputDecorationThemeData(constraints:)`.
8103    pub fn constraints(mut self, constraints: BoxConstraints) -> InputDecorationThemeData {
8104        self.constraints = Some(constraints);
8105        self
8106    }
8107
8108    /// Dart `InputDecorationThemeData(visualDensity:)`.
8109    pub fn visual_density(mut self, visual_density: VisualDensity) -> InputDecorationThemeData {
8110        self.visual_density = Some(visual_density);
8111        self
8112    }
8113
8114    /// Dart `InputDecorationThemeData(supportingTextPadding:)`.
8115    pub fn supporting_text_padding(
8116        mut self,
8117        supporting_text_padding: impl Into<EdgeInsetsGeometry>,
8118    ) -> InputDecorationThemeData {
8119        let supporting_text_padding = supporting_text_padding.into();
8120        self.supporting_text_padding = Some(supporting_text_padding);
8121        self
8122    }
8123
8124    /// Creates a copy of this object but with the given fields replaced with the
8125    /// new values.
8126    ///
8127    /// Dart's named arguments are the fluent setters on the copy
8128    /// (`theme.copy_with().fill_color(color)`).
8129    pub fn copy_with(&self) -> InputDecorationThemeData {
8130        self.clone()
8131    }
8132
8133    /// Returns a copy of this InputDecorationThemeData where the non-null fields in
8134    /// the given InputDecorationThemeData override the corresponding nullable fields
8135    /// in this InputDecorationThemeData.
8136    ///
8137    /// The non-nullable fields of InputDecorationThemeData, such as
8138    /// `floating_label_behavior`, `is_dense`, `is_collapsed`, `filled`, and
8139    /// `align_label_with_hint` cannot be overridden.
8140    ///
8141    /// In other words, the fields of the provided `InputDecorationThemeData`
8142    /// are used to fill in the unspecified and nullable fields of this
8143    /// InputDecorationThemeData.
8144    pub fn merge(&self, other: Option<&InputDecorationThemeData>) -> InputDecorationThemeData {
8145        let Some(other) = other else {
8146            return self.clone();
8147        };
8148        let mut merged = self.copy_with();
8149        merged.label_style = self
8150            .label_style
8151            .clone()
8152            .or_else(|| other.label_style.clone());
8153        merged.floating_label_style = self
8154            .floating_label_style
8155            .clone()
8156            .or_else(|| other.floating_label_style.clone());
8157        merged.helper_style = self
8158            .helper_style
8159            .clone()
8160            .or_else(|| other.helper_style.clone());
8161        merged.helper_max_lines = self.helper_max_lines.or(other.helper_max_lines);
8162        merged.hint_style = self.hint_style.clone().or_else(|| other.hint_style.clone());
8163        merged.hint_fade_duration = self.hint_fade_duration.or(other.hint_fade_duration);
8164        merged.hint_max_lines = self.hint_max_lines.or(other.hint_max_lines);
8165        merged.error_style = self
8166            .error_style
8167            .clone()
8168            .or_else(|| other.error_style.clone());
8169        merged.error_max_lines = self.error_max_lines.or(other.error_max_lines);
8170        merged.content_padding = self.content_padding.or(other.content_padding);
8171        merged.icon_color = self.icon_color.clone().or_else(|| other.icon_color.clone());
8172        merged.prefix_style = self
8173            .prefix_style
8174            .clone()
8175            .or_else(|| other.prefix_style.clone());
8176        merged.prefix_icon_color = self
8177            .prefix_icon_color
8178            .clone()
8179            .or_else(|| other.prefix_icon_color.clone());
8180        merged.prefix_icon_constraints = self
8181            .prefix_icon_constraints
8182            .or(other.prefix_icon_constraints);
8183        merged.suffix_style = self
8184            .suffix_style
8185            .clone()
8186            .or_else(|| other.suffix_style.clone());
8187        merged.suffix_icon_color = self
8188            .suffix_icon_color
8189            .clone()
8190            .or_else(|| other.suffix_icon_color.clone());
8191        merged.suffix_icon_constraints = self
8192            .suffix_icon_constraints
8193            .or(other.suffix_icon_constraints);
8194        merged.counter_style = self
8195            .counter_style
8196            .clone()
8197            .or_else(|| other.counter_style.clone());
8198        merged.fill_color = self.fill_color.clone().or_else(|| other.fill_color.clone());
8199        merged.active_indicator_border = self
8200            .active_indicator_border
8201            .clone()
8202            .or_else(|| other.active_indicator_border.clone());
8203        merged.outline_border = self
8204            .outline_border
8205            .clone()
8206            .or_else(|| other.outline_border.clone());
8207        merged.focus_color = self.focus_color.or(other.focus_color);
8208        merged.hover_color = self.hover_color.or(other.hover_color);
8209        merged.error_border = self
8210            .error_border
8211            .clone()
8212            .or_else(|| other.error_border.clone());
8213        merged.focused_border = self
8214            .focused_border
8215            .clone()
8216            .or_else(|| other.focused_border.clone());
8217        merged.focused_error_border = self
8218            .focused_error_border
8219            .clone()
8220            .or_else(|| other.focused_error_border.clone());
8221        merged.disabled_border = self
8222            .disabled_border
8223            .clone()
8224            .or_else(|| other.disabled_border.clone());
8225        merged.enabled_border = self
8226            .enabled_border
8227            .clone()
8228            .or_else(|| other.enabled_border.clone());
8229        merged.border = self.border.clone().or_else(|| other.border.clone());
8230        merged.constraints = self.constraints.or(other.constraints);
8231        merged.visual_density = self.visual_density.or(other.visual_density);
8232        merged.supporting_text_padding = self
8233            .supporting_text_padding
8234            .or(other.supporting_text_padding);
8235        merged
8236    }
8237}
8238
8239impl Default for InputDecorationThemeData {
8240    fn default() -> InputDecorationThemeData {
8241        InputDecorationThemeData::new()
8242    }
8243}
8244
8245/// Dart's `toString` through `debugFillProperties`: the properties that differ from
8246/// `InputDecorationThemeData()`'s.
8247impl Debug for InputDecorationThemeData {
8248    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8249        let default_theme = InputDecorationThemeData::new();
8250        let mut properties: Vec<String> = Vec::new();
8251        if let Some(label_style) = &self.label_style {
8252            properties.push(format!("labelStyle: {:?}", label_style));
8253        }
8254        if let Some(floating_label_style) = &self.floating_label_style {
8255            properties.push(format!("floatingLabelStyle: {:?}", floating_label_style));
8256        }
8257        if let Some(helper_style) = &self.helper_style {
8258            properties.push(format!("helperStyle: {:?}", helper_style));
8259        }
8260        if let Some(helper_max_lines) = &self.helper_max_lines {
8261            properties.push(format!("helperMaxLines: {:?}", helper_max_lines));
8262        }
8263        if let Some(hint_style) = &self.hint_style {
8264            properties.push(format!("hintStyle: {:?}", hint_style));
8265        }
8266        if let Some(hint_fade_duration) = &self.hint_fade_duration {
8267            properties.push(format!("hintFadeDuration: {:?}", hint_fade_duration));
8268        }
8269        if let Some(hint_max_lines) = &self.hint_max_lines {
8270            properties.push(format!("hintMaxLines: {:?}", hint_max_lines));
8271        }
8272        if let Some(error_style) = &self.error_style {
8273            properties.push(format!("errorStyle: {:?}", error_style));
8274        }
8275        if let Some(error_max_lines) = &self.error_max_lines {
8276            properties.push(format!("errorMaxLines: {:?}", error_max_lines));
8277        }
8278        if self.floating_label_behavior != default_theme.floating_label_behavior {
8279            properties.push(format!(
8280                "floatingLabelBehavior: {:?}",
8281                self.floating_label_behavior
8282            ));
8283        }
8284        if self.floating_label_alignment != default_theme.floating_label_alignment {
8285            properties.push(format!(
8286                "floatingLabelAlignment: {:?}",
8287                self.floating_label_alignment
8288            ));
8289        }
8290        if self.is_dense != default_theme.is_dense {
8291            properties.push(format!("isDense: {:?}", self.is_dense));
8292        }
8293        if let Some(content_padding) = &self.content_padding {
8294            properties.push(format!("contentPadding: {:?}", content_padding));
8295        }
8296        if let Some(supporting_text_padding) = &self.supporting_text_padding {
8297            properties.push(format!(
8298                "supportingTextPadding: {:?}",
8299                supporting_text_padding
8300            ));
8301        }
8302        if self.is_collapsed != default_theme.is_collapsed {
8303            properties.push(format!("isCollapsed: {:?}", self.is_collapsed));
8304        }
8305        if let Some(icon_color) = &self.icon_color {
8306            properties.push(format!("iconColor: {:?}", icon_color));
8307        }
8308        if let Some(prefix_icon_color) = &self.prefix_icon_color {
8309            properties.push(format!("prefixIconColor: {:?}", prefix_icon_color));
8310        }
8311        if let Some(prefix_icon_constraints) = &self.prefix_icon_constraints {
8312            properties.push(format!(
8313                "prefixIconConstraints: {:?}",
8314                prefix_icon_constraints
8315            ));
8316        }
8317        if let Some(prefix_style) = &self.prefix_style {
8318            properties.push(format!("prefixStyle: {:?}", prefix_style));
8319        }
8320        if let Some(suffix_icon_color) = &self.suffix_icon_color {
8321            properties.push(format!("suffixIconColor: {:?}", suffix_icon_color));
8322        }
8323        if let Some(suffix_icon_constraints) = &self.suffix_icon_constraints {
8324            properties.push(format!(
8325                "suffixIconConstraints: {:?}",
8326                suffix_icon_constraints
8327            ));
8328        }
8329        if let Some(suffix_style) = &self.suffix_style {
8330            properties.push(format!("suffixStyle: {:?}", suffix_style));
8331        }
8332        if let Some(counter_style) = &self.counter_style {
8333            properties.push(format!("counterStyle: {:?}", counter_style));
8334        }
8335        if self.filled != default_theme.filled {
8336            properties.push(format!("filled: {:?}", self.filled));
8337        }
8338        if let Some(fill_color) = &self.fill_color {
8339            properties.push(format!("fillColor: {:?}", fill_color));
8340        }
8341        if let Some(active_indicator_border) = &self.active_indicator_border {
8342            properties.push(format!(
8343                "activeIndicatorBorder: {:?}",
8344                active_indicator_border
8345            ));
8346        }
8347        if let Some(outline_border) = &self.outline_border {
8348            properties.push(format!("outlineBorder: {:?}", outline_border));
8349        }
8350        if let Some(focus_color) = &self.focus_color {
8351            properties.push(format!("focusColor: {:?}", focus_color));
8352        }
8353        if let Some(hover_color) = &self.hover_color {
8354            properties.push(format!("hoverColor: {:?}", hover_color));
8355        }
8356        if let Some(error_border) = &self.error_border {
8357            properties.push(format!("errorBorder: {:?}", error_border));
8358        }
8359        if let Some(focused_border) = &self.focused_border {
8360            properties.push(format!("focusedBorder: {:?}", focused_border));
8361        }
8362        if let Some(focused_error_border) = &self.focused_error_border {
8363            properties.push(format!("focusedErrorBorder: {:?}", focused_error_border));
8364        }
8365        if let Some(disabled_border) = &self.disabled_border {
8366            properties.push(format!("disabledBorder: {:?}", disabled_border));
8367        }
8368        if let Some(enabled_border) = &self.enabled_border {
8369            properties.push(format!("enabledBorder: {:?}", enabled_border));
8370        }
8371        if let Some(border) = &self.border {
8372            properties.push(format!("border: {:?}", border));
8373        }
8374        if self.align_label_with_hint != default_theme.align_label_with_hint {
8375            properties.push(format!(
8376                "alignLabelWithHint: {:?}",
8377                self.align_label_with_hint
8378            ));
8379        }
8380        if let Some(constraints) = &self.constraints {
8381            properties.push(format!("constraints: {:?}", constraints));
8382        }
8383        if let Some(visual_density) = &self.visual_density {
8384            properties.push(format!("visualDensity: {:?}", visual_density));
8385        }
8386        write!(f, "InputDecorationThemeData({})", properties.join(", "))
8387    }
8388}
8389
8390impl Diagnosticable for InputDecorationThemeData {
8391    fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder) {
8392        let default_theme = InputDecorationThemeData::new();
8393        properties.add(
8394            DiagnosticsProperty::<AnyTextStyle>::new("labelStyle", self.label_style.clone())
8395                .default_value(default_theme.label_style.clone()),
8396        );
8397        properties.add(
8398            DiagnosticsProperty::<AnyTextStyle>::new(
8399                "floatingLabelStyle",
8400                self.floating_label_style.clone(),
8401            )
8402            .default_value(default_theme.floating_label_style.clone()),
8403        );
8404        properties.add(
8405            DiagnosticsProperty::<AnyTextStyle>::new("helperStyle", self.helper_style.clone())
8406                .default_value(default_theme.helper_style.clone()),
8407        );
8408        properties.add(
8409            IntProperty::<i32>::new("helperMaxLines", self.helper_max_lines)
8410                .default_value(default_theme.helper_max_lines),
8411        );
8412        properties.add(
8413            DiagnosticsProperty::<AnyTextStyle>::new("hintStyle", self.hint_style.clone())
8414                .default_value(default_theme.hint_style.clone()),
8415        );
8416        properties.add(
8417            DiagnosticsProperty::<SignedDuration>::new(
8418                "hintFadeDuration",
8419                self.hint_fade_duration.map(SignedDuration::from),
8420            )
8421            .default_value(default_theme.hint_fade_duration.map(SignedDuration::from)),
8422        );
8423        properties.add(
8424            IntProperty::<i32>::new("hintMaxLines", self.hint_max_lines)
8425                .default_value(default_theme.hint_max_lines),
8426        );
8427        properties.add(
8428            DiagnosticsProperty::<AnyTextStyle>::new("errorStyle", self.error_style.clone())
8429                .default_value(default_theme.error_style.clone()),
8430        );
8431        properties.add(
8432            IntProperty::<i32>::new("errorMaxLines", self.error_max_lines)
8433                .default_value(default_theme.error_max_lines),
8434        );
8435        properties.add(
8436            DiagnosticsProperty::<waft_foundation::DartEnum<FloatingLabelBehavior>>::new(
8437                "floatingLabelBehavior",
8438                Some(waft_foundation::DartEnum(self.floating_label_behavior)),
8439            )
8440            .default_value(Some(waft_foundation::DartEnum(
8441                default_theme.floating_label_behavior,
8442            ))),
8443        );
8444        properties.add(
8445            DiagnosticsProperty::<String>::new(
8446                "floatingLabelAlignment",
8447                Some(format!("{:?}", self.floating_label_alignment)),
8448            )
8449            .default_value(Some(format!(
8450                "{:?}",
8451                default_theme.floating_label_alignment
8452            ))),
8453        );
8454        properties.add(
8455            DiagnosticsProperty::<bool>::new("isDense", Some(self.is_dense))
8456                .default_value(Some(default_theme.is_dense)),
8457        );
8458        properties.add(
8459            DiagnosticsProperty::<EdgeInsetsGeometry>::new("contentPadding", self.content_padding)
8460                .default_value(default_theme.content_padding),
8461        );
8462        properties.add(
8463            DiagnosticsProperty::<bool>::new("isCollapsed", Some(self.is_collapsed))
8464                .default_value(Some(default_theme.is_collapsed)),
8465        );
8466        properties.add(
8467            DiagnosticsProperty::<AnyColor>::new("iconColor", self.icon_color.clone())
8468                .default_value(default_theme.icon_color.clone()),
8469        );
8470        properties.add(
8471            DiagnosticsProperty::<AnyColor>::new("prefixIconColor", self.prefix_icon_color.clone())
8472                .default_value(default_theme.prefix_icon_color.clone()),
8473        );
8474        properties.add(
8475            DiagnosticsProperty::<BoxConstraints>::new(
8476                "prefixIconConstraints",
8477                self.prefix_icon_constraints,
8478            )
8479            .default_value(default_theme.prefix_icon_constraints),
8480        );
8481        properties.add(
8482            DiagnosticsProperty::<AnyTextStyle>::new("prefixStyle", self.prefix_style.clone())
8483                .default_value(default_theme.prefix_style.clone()),
8484        );
8485        properties.add(
8486            DiagnosticsProperty::<AnyColor>::new("suffixIconColor", self.suffix_icon_color.clone())
8487                .default_value(default_theme.suffix_icon_color.clone()),
8488        );
8489        properties.add(
8490            DiagnosticsProperty::<BoxConstraints>::new(
8491                "suffixIconConstraints",
8492                self.suffix_icon_constraints,
8493            )
8494            .default_value(default_theme.suffix_icon_constraints),
8495        );
8496        properties.add(
8497            DiagnosticsProperty::<AnyTextStyle>::new("suffixStyle", self.suffix_style.clone())
8498                .default_value(default_theme.suffix_style.clone()),
8499        );
8500        properties.add(
8501            DiagnosticsProperty::<AnyTextStyle>::new("counterStyle", self.counter_style.clone())
8502                .default_value(default_theme.counter_style.clone()),
8503        );
8504        properties.add(
8505            DiagnosticsProperty::<bool>::new("filled", Some(self.filled))
8506                .default_value(Some(default_theme.filled)),
8507        );
8508        properties.add(
8509            DiagnosticsProperty::<AnyColor>::new("fillColor", self.fill_color.clone())
8510                .default_value(default_theme.fill_color.clone()),
8511        );
8512        properties.add(
8513            DiagnosticsProperty::<String>::new(
8514                "activeIndicatorBorder",
8515                self.active_indicator_border
8516                    .as_ref()
8517                    .map(|border| format!("{border:?}")),
8518            )
8519            .default_value(
8520                default_theme
8521                    .active_indicator_border
8522                    .as_ref()
8523                    .map(|border| format!("{border:?}")),
8524            ),
8525        );
8526        properties.add(
8527            DiagnosticsProperty::<String>::new(
8528                "outlineBorder",
8529                self.outline_border
8530                    .as_ref()
8531                    .map(|border| format!("{border:?}")),
8532            )
8533            .default_value(
8534                default_theme
8535                    .outline_border
8536                    .as_ref()
8537                    .map(|border| format!("{border:?}")),
8538            ),
8539        );
8540        properties.add(
8541            ColorProperty::new("focusColor", self.focus_color)
8542                .default_value(default_theme.focus_color),
8543        );
8544        properties.add(
8545            ColorProperty::new("hoverColor", self.hover_color)
8546                .default_value(default_theme.hover_color),
8547        );
8548        properties.add(
8549            DiagnosticsProperty::<String>::new(
8550                "errorBorder",
8551                self.error_border
8552                    .as_ref()
8553                    .map(|border| format!("{border:?}")),
8554            )
8555            .default_value(
8556                default_theme
8557                    .error_border
8558                    .as_ref()
8559                    .map(|border| format!("{border:?}")),
8560            ),
8561        );
8562        properties.add(
8563            DiagnosticsProperty::<String>::new(
8564                "focusedBorder",
8565                self.focused_border
8566                    .as_ref()
8567                    .map(|border| format!("{border:?}")),
8568            )
8569            .default_value(
8570                default_theme
8571                    .focused_error_border
8572                    .as_ref()
8573                    .map(|border| format!("{border:?}")),
8574            ),
8575        );
8576        properties.add(
8577            DiagnosticsProperty::<String>::new(
8578                "focusedErrorBorder",
8579                self.focused_error_border
8580                    .as_ref()
8581                    .map(|border| format!("{border:?}")),
8582            )
8583            .default_value(
8584                default_theme
8585                    .focused_error_border
8586                    .as_ref()
8587                    .map(|border| format!("{border:?}")),
8588            ),
8589        );
8590        properties.add(
8591            DiagnosticsProperty::<String>::new(
8592                "disabledBorder",
8593                self.disabled_border
8594                    .as_ref()
8595                    .map(|border| format!("{border:?}")),
8596            )
8597            .default_value(
8598                default_theme
8599                    .disabled_border
8600                    .as_ref()
8601                    .map(|border| format!("{border:?}")),
8602            ),
8603        );
8604        properties.add(
8605            DiagnosticsProperty::<String>::new(
8606                "enabledBorder",
8607                self.enabled_border
8608                    .as_ref()
8609                    .map(|border| format!("{border:?}")),
8610            )
8611            .default_value(
8612                default_theme
8613                    .enabled_border
8614                    .as_ref()
8615                    .map(|border| format!("{border:?}")),
8616            ),
8617        );
8618        properties.add(
8619            DiagnosticsProperty::<String>::new(
8620                "border",
8621                self.border.as_ref().map(|border| format!("{border:?}")),
8622            )
8623            .default_value(
8624                default_theme
8625                    .border
8626                    .as_ref()
8627                    .map(|border| format!("{border:?}")),
8628            ),
8629        );
8630        properties.add(
8631            DiagnosticsProperty::<bool>::new(
8632                "alignLabelWithHint",
8633                Some(self.align_label_with_hint),
8634            )
8635            .default_value(Some(default_theme.align_label_with_hint)),
8636        );
8637        properties.add(
8638            DiagnosticsProperty::<BoxConstraints>::new("constraints", self.constraints)
8639                .default_value(default_theme.constraints),
8640        );
8641        properties.add(
8642            DiagnosticsProperty::<crate::theme_data::VisualDensity>::new(
8643                "visualDensity",
8644                self.visual_density,
8645            )
8646            .default_value(default_theme.visual_density),
8647        );
8648    }
8649}
8650
8651/// Dart's `InputDecorationThemeData.toString`, through its diagnostics.
8652impl fmt::Display for InputDecorationThemeData {
8653    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8654        f.write_str(&Diagnosticable::to_string(self))
8655    }
8656}
8657
8658/// Dart's `_InputDecoratorDefaultsM2`.
8659struct InputDecoratorDefaultsM2 {
8660    /// Dart's `super(..)` arguments.
8661    input_decoration_theme_data: InputDecorationThemeData,
8662    context: DefaultsContext,
8663}
8664
8665impl InputDecoratorDefaultsM2 {
8666    fn new(context: BuildContext) -> InputDecoratorDefaultsM2 {
8667        InputDecoratorDefaultsM2 {
8668            input_decoration_theme_data: InputDecorationThemeData::new(),
8669            context: DefaultsContext::new(context),
8670        }
8671    }
8672}
8673
8674impl InputDecorationThemeDataGetters for InputDecoratorDefaultsM2 {
8675    fn input_decoration_theme_data(&self) -> &InputDecorationThemeData {
8676        &self.input_decoration_theme_data
8677    }
8678
8679    fn hint_style(&self, app: &mut App) -> Option<AnyTextStyle> {
8680        let theme = self.context.theme(app);
8681        let disabled_color = theme.disabled_color;
8682        let hint_color = theme.hint_color;
8683        let hint_style = WidgetStateTextStyle::resolve_with(move |states: &WidgetStates| {
8684            if states.contains(&WidgetState::Disabled) {
8685                return TextStyle::new().color(disabled_color);
8686            }
8687            TextStyle::new().color(hint_color)
8688        });
8689        Some(hint_style.into())
8690    }
8691
8692    fn label_style(&self, app: &mut App) -> Option<AnyTextStyle> {
8693        let theme = self.context.theme(app);
8694        let disabled_color = theme.disabled_color;
8695        let hint_color = theme.hint_color;
8696        let label_style = WidgetStateTextStyle::resolve_with(move |states: &WidgetStates| {
8697            if states.contains(&WidgetState::Disabled) {
8698                return TextStyle::new().color(disabled_color);
8699            }
8700            TextStyle::new().color(hint_color)
8701        });
8702        Some(label_style.into())
8703    }
8704
8705    fn floating_label_style(&self, app: &mut App) -> Option<AnyTextStyle> {
8706        let theme = self.context.theme(app);
8707        let disabled_color = theme.disabled_color;
8708        let hint_color = theme.hint_color;
8709        let error = theme.color_scheme.error();
8710        let primary = theme.color_scheme.primary();
8711        let floating_label_style =
8712            WidgetStateTextStyle::resolve_with(move |states: &WidgetStates| {
8713                if states.contains(&WidgetState::Disabled) {
8714                    return TextStyle::new().color(disabled_color);
8715                }
8716                if states.contains(&WidgetState::Error) {
8717                    return TextStyle::new().color(error);
8718                }
8719                if states.contains(&WidgetState::Focused) {
8720                    return TextStyle::new().color(primary);
8721                }
8722                TextStyle::new().color(hint_color)
8723            });
8724        Some(floating_label_style.into())
8725    }
8726
8727    fn helper_style(&self, app: &mut App) -> Option<AnyTextStyle> {
8728        let theme = self.context.theme(app);
8729        let hint_color = theme.hint_color;
8730        let body_small = theme.text_theme.body_small.clone();
8731        let helper_body_small = body_small.clone();
8732        let helper_style = WidgetStateTextStyle::resolve_with(move |states: &WidgetStates| {
8733            let body_small = helper_body_small
8734                .clone()
8735                .expect("ThemeData::text_theme has a body_small");
8736            if states.contains(&WidgetState::Disabled) {
8737                return body_small.copy_with().color(Colors::TRANSPARENT);
8738            }
8739
8740            body_small.copy_with().color(hint_color)
8741        });
8742        Some(helper_style.into())
8743    }
8744
8745    fn error_style(&self, app: &mut App) -> Option<AnyTextStyle> {
8746        let theme = self.context.theme(app);
8747        let error = theme.color_scheme.error();
8748        let body_small = theme.text_theme.body_small.clone();
8749        let error_style = WidgetStateTextStyle::resolve_with(move |states: &WidgetStates| {
8750            let body_small = body_small
8751                .clone()
8752                .expect("ThemeData::text_theme has a body_small");
8753            if states.contains(&WidgetState::Disabled) {
8754                return body_small.copy_with().color(Colors::TRANSPARENT);
8755            }
8756            body_small.copy_with().color(error)
8757        });
8758        Some(error_style.into())
8759    }
8760
8761    fn fill_color(&self, app: &mut App) -> Option<AnyColor> {
8762        let brightness = Theme::brightness_of(app, self.context.context());
8763        let fill_color = WidgetStateColor::resolve_with(move |states: &WidgetStates| {
8764            match (brightness, states.contains(&WidgetState::Disabled)) {
8765                (Brightness::Dark, true) => Color::new(0x0DFFFFFF), //  5% white
8766                (Brightness::Dark, false) => Color::new(0x1AFFFFFF), // 10% white
8767                (Brightness::Light, true) => Color::new(0x05000000), //  2% black
8768                (Brightness::Light, false) => Color::new(0x0A000000), //  4% black
8769            }
8770        });
8771        Some(fill_color.into())
8772    }
8773
8774    fn icon_color(&self, app: &mut App) -> Option<AnyColor> {
8775        let theme = self.context.theme(app);
8776        let brightness = Theme::brightness_of(app, self.context.context());
8777        let disabled_color = theme.disabled_color;
8778        let primary = theme.color_scheme.primary();
8779        let icon_color = WidgetStateColor::resolve_with(move |states: &WidgetStates| {
8780            if states.contains(&WidgetState::Disabled) && !states.contains(&WidgetState::Focused) {
8781                return disabled_color;
8782            }
8783            if states.contains(&WidgetState::Focused) {
8784                return primary;
8785            }
8786            match brightness {
8787                Brightness::Dark => Colors::WHITE70,
8788                Brightness::Light => Colors::BLACK45,
8789            }
8790        });
8791        Some(icon_color.into())
8792    }
8793
8794    fn prefix_icon_color(&self, app: &mut App) -> Option<AnyColor> {
8795        let theme = self.context.theme(app);
8796        let brightness = Theme::brightness_of(app, self.context.context());
8797        let disabled_color = theme.disabled_color;
8798        let primary = theme.color_scheme.primary();
8799        let prefix_icon_color = WidgetStateColor::resolve_with(move |states: &WidgetStates| {
8800            if states.contains(&WidgetState::Disabled) && !states.contains(&WidgetState::Focused) {
8801                return disabled_color;
8802            }
8803            if states.contains(&WidgetState::Focused) {
8804                return primary;
8805            }
8806            match brightness {
8807                Brightness::Dark => Colors::WHITE70,
8808                Brightness::Light => Colors::BLACK45,
8809            }
8810        });
8811        Some(prefix_icon_color.into())
8812    }
8813
8814    fn suffix_icon_color(&self, app: &mut App) -> Option<AnyColor> {
8815        let theme = self.context.theme(app);
8816        let brightness = Theme::brightness_of(app, self.context.context());
8817        let disabled_color = theme.disabled_color;
8818        let error = theme.color_scheme.error();
8819        let primary = theme.color_scheme.primary();
8820        let suffix_icon_color = WidgetStateColor::resolve_with(move |states: &WidgetStates| {
8821            if states.contains(&WidgetState::Disabled) && !states.contains(&WidgetState::Focused) {
8822                return disabled_color;
8823            }
8824            if states.contains(&WidgetState::Error) {
8825                return error;
8826            }
8827            if states.contains(&WidgetState::Focused) {
8828                return primary;
8829            }
8830            match brightness {
8831                Brightness::Dark => Colors::WHITE70,
8832                Brightness::Light => Colors::BLACK45,
8833            }
8834        });
8835        Some(suffix_icon_color.into())
8836    }
8837}
8838
8839#[cfg(test)]
8840pub(crate) mod tests {
8841    pub(crate) mod common {
8842        // The helpers of input_decorator_test.dart.
8843        //
8844        use waft_widgets::testing::WidgetTester;
8845
8846        use std::time::Duration;
8847
8848        use waft_embedder::{Color, Offset, Rect};
8849        use waft_painting::{
8850            Alignment, AlignmentGeometry, BorderRadius, BorderSide, TextAlignVertical,
8851            TextDirection, TextStyle,
8852        };
8853        use waft_rendering::AnyRenderBox;
8854        use waft_widgets::{
8855            Align, AnyElement, Builder, CustomPaint, Directionality, IntoWidget, IntrinsicWidth,
8856            MatrixTransition, WidgetRef, downcast_widget,
8857        };
8858
8859        use crate::test_support::PaintInspection;
8860        use waft_embedder::valo::Op;
8861        pub(super) use waft_rendering::testing::{PaintCall, PaintedStyle, assert_paints, paints};
8862        pub(super) use waft_widgets::testing::{
8863            assert_f32_equals, assert_more_or_less_equals_within, expect, find, finds_nothing,
8864            finds_one_widget,
8865        };
8866
8867        use super::super::*;
8868        use crate::app::MaterialApp;
8869        use crate::icon_button_theme::IconButtonThemeData;
8870        use crate::input_border::{InputBorderRef, OutlineInputBorder, UnderlineInputBorder};
8871        use crate::material::Material;
8872        use crate::theme::Theme;
8873        use crate::theme_data::{ThemeData, VisualDensity};
8874
8875        pub(super) const K_TRANSITION_DURATION: Duration = Duration::from_millis(167);
8876
8877        pub(super) const HINT_TEXT: &str = "hint";
8878        pub(super) const INPUT_TEXT: &str = "text";
8879        pub(super) const LABEL_TEXT: &str = "label";
8880        pub(super) const ERROR_TEXT: &str = "error";
8881        pub(super) const HELPER_TEXT: &str = "helper";
8882        pub(super) const COUNTER_TEXT: &str = "counter";
8883
8884        pub(super) const TWO_LINES: &str = "line1\nline2";
8885        pub(super) const THREE_LINES: &str = "line1\nline2\nline3";
8886
8887        /// Dart's `ThemeData()`.
8888        pub(super) fn m3(app: &App) -> ThemeData {
8889            ThemeData::builder().build(app)
8890        }
8891
8892        /// Dart's `ThemeData(useMaterial3: false)`.
8893        pub(super) fn m2(app: &App) -> ThemeData {
8894            ThemeData::builder().use_material3(false).build(app)
8895        }
8896
8897        /// Dart's input child: `Text(inputText, style: TextStyle(fontSize: 16.0, fontWeight:
8898        /// FontWeight.w400, letterSpacing: 0.5, height: 1.50))`, a text style compliant with M3
8899        /// specification (which is bodyLarge for text fields).
8900        pub(super) fn input_text() -> WidgetRef {
8901            Text::new(INPUT_TEXT)
8902                .style(
8903                    TextStyle::new()
8904                        .font_size(16.0)
8905                        .font_weight(waft_painting::FontWeight::W400)
8906                        .letter_spacing(0.5)
8907                        .height(1.50),
8908                )
8909                .into_widget()
8910        }
8911
8912        /// Dart's `buildInputDecorator`, its named arguments the setters.
8913        pub(super) struct BuildInputDecorator {
8914            decoration: InputDecoration,
8915            theme: Option<fn(&App) -> ThemeData>,
8916            input_decoration_theme: Option<InputDecorationThemeData>,
8917            local_input_decoration_theme: Option<InputDecorationThemeData>,
8918            icon_button_theme: Option<IconButtonThemeData>,
8919            text_direction: TextDirection,
8920            expands: bool,
8921            is_empty: bool,
8922            is_focused: bool,
8923            is_hovering: bool,
8924            use_intrinsic_width: bool,
8925            base_style: Option<TextStyle>,
8926            text_align_vertical: Option<TextAlignVertical>,
8927            visual_density: Option<VisualDensity>,
8928            child: Option<WidgetRef>,
8929        }
8930
8931        // Every argument of Dart's helper is a setter, named after it, whether or not a ported
8932        // case passes it.
8933        #[allow(dead_code, clippy::wrong_self_convention)]
8934        impl BuildInputDecorator {
8935            pub(super) fn new(decoration: InputDecoration) -> BuildInputDecorator {
8936                BuildInputDecorator {
8937                    decoration,
8938                    theme: None,
8939                    input_decoration_theme: None,
8940                    local_input_decoration_theme: None,
8941                    icon_button_theme: None,
8942                    text_direction: TextDirection::Ltr,
8943                    expands: false,
8944                    is_empty: false,
8945                    is_focused: false,
8946                    is_hovering: false,
8947                    use_intrinsic_width: false,
8948                    base_style: None,
8949                    text_align_vertical: None,
8950                    visual_density: None,
8951                    child: None,
8952                }
8953            }
8954
8955            pub(super) fn theme(mut self, theme: fn(&App) -> ThemeData) -> BuildInputDecorator {
8956                self.theme = Some(theme);
8957                self
8958            }
8959
8960            pub(super) fn input_decoration_theme(
8961                mut self,
8962                theme: InputDecorationThemeData,
8963            ) -> BuildInputDecorator {
8964                self.input_decoration_theme = Some(theme);
8965                self
8966            }
8967
8968            pub(super) fn local_input_decoration_theme(
8969                mut self,
8970                theme: InputDecorationThemeData,
8971            ) -> BuildInputDecorator {
8972                self.local_input_decoration_theme = Some(theme);
8973                self
8974            }
8975
8976            pub(super) fn icon_button_theme(
8977                mut self,
8978                theme: IconButtonThemeData,
8979            ) -> BuildInputDecorator {
8980                self.icon_button_theme = Some(theme);
8981                self
8982            }
8983
8984            pub(super) fn text_direction(
8985                mut self,
8986                text_direction: TextDirection,
8987            ) -> BuildInputDecorator {
8988                self.text_direction = text_direction;
8989                self
8990            }
8991
8992            pub(super) fn expands(mut self, expands: bool) -> BuildInputDecorator {
8993                self.expands = expands;
8994                self
8995            }
8996
8997            pub(super) fn is_empty(mut self, is_empty: bool) -> BuildInputDecorator {
8998                self.is_empty = is_empty;
8999                self
9000            }
9001
9002            pub(super) fn is_focused(mut self, is_focused: bool) -> BuildInputDecorator {
9003                self.is_focused = is_focused;
9004                self
9005            }
9006
9007            pub(super) fn is_hovering(mut self, is_hovering: bool) -> BuildInputDecorator {
9008                self.is_hovering = is_hovering;
9009                self
9010            }
9011
9012            pub(super) fn use_intrinsic_width(
9013                mut self,
9014                use_intrinsic_width: bool,
9015            ) -> BuildInputDecorator {
9016                self.use_intrinsic_width = use_intrinsic_width;
9017                self
9018            }
9019
9020            pub(super) fn base_style(mut self, base_style: TextStyle) -> BuildInputDecorator {
9021                self.base_style = Some(base_style);
9022                self
9023            }
9024
9025            pub(super) fn text_align_vertical(
9026                mut self,
9027                text_align_vertical: TextAlignVertical,
9028            ) -> BuildInputDecorator {
9029                self.text_align_vertical = Some(text_align_vertical);
9030                self
9031            }
9032
9033            pub(super) fn visual_density(
9034                mut self,
9035                visual_density: VisualDensity,
9036            ) -> BuildInputDecorator {
9037                self.visual_density = Some(visual_density);
9038                self
9039            }
9040
9041            pub(super) fn child<K>(mut self, child: impl IntoWidget<K>) -> BuildInputDecorator {
9042                self.child = Some(child.into_widget());
9043                self
9044            }
9045
9046            pub(super) fn build(self) -> WidgetRef {
9047                let mut decorator = InputDecorator::new(self.decoration)
9048                    .expands(self.expands)
9049                    .is_empty(self.is_empty)
9050                    .is_focused(self.is_focused)
9051                    .is_hovering(self.is_hovering)
9052                    .child(self.child.unwrap_or_else(input_text));
9053                if let Some(base_style) = self.base_style {
9054                    decorator = decorator.base_style(base_style);
9055                }
9056                if let Some(text_align_vertical) = self.text_align_vertical {
9057                    decorator = decorator.text_align_vertical(text_align_vertical);
9058                }
9059                let mut widget = decorator.into_widget();
9060
9061                if self.use_intrinsic_width {
9062                    widget = IntrinsicWidth::new().child(widget).into_widget();
9063                }
9064
9065                if let Some(local) = self.local_input_decoration_theme {
9066                    widget = InputDecorationTheme::new()
9067                        .with_data(local)
9068                        .child(widget)
9069                        .into_widget();
9070                }
9071
9072                let theme = self.theme;
9073                let input_decoration_theme = self.input_decoration_theme;
9074                let icon_button_theme = self.icon_button_theme;
9075                let visual_density = self.visual_density;
9076                let text_direction = self.text_direction;
9077                MaterialApp::new()
9078                    .home(Material::new().child(Builder::new(move |app, context| {
9079                        let base = match theme {
9080                            Some(theme) => Rc::new(theme(app)),
9081                            None => Theme::of(app, context),
9082                        };
9083                        let mut copy = base.copy_with();
9084                        if let Some(input_decoration_theme) = &input_decoration_theme {
9085                            copy = copy.input_decoration_theme(input_decoration_theme.clone());
9086                        }
9087                        if let Some(icon_button_theme) = &icon_button_theme {
9088                            copy = copy.icon_button_theme(icon_button_theme.clone());
9089                        }
9090                        if let Some(visual_density) = visual_density {
9091                            copy = copy.visual_density(visual_density);
9092                        }
9093                        Theme::new(
9094                            copy.build(),
9095                            Align::new()
9096                                .alignment(AlignmentGeometry::Alignment(Alignment::TOP_LEFT))
9097                                .child(Directionality::new(text_direction, widget.clone())),
9098                        )
9099                        .into_widget()
9100                    })))
9101                    .into_widget()
9102            }
9103        }
9104
9105        /// Dart's `tester.getRect(find.byType(InputDecorator))`.
9106        pub(super) fn get_decorator_rect(tester: &WidgetTester) -> Rect {
9107            tester.get_rect(find::by_type::<InputDecorator>())
9108        }
9109
9110        /// The ops the render object of `element` and its subtree record.
9111        pub(super) fn ops_of(tester: &WidgetTester, element: AnyElement) -> Vec<Op> {
9112            tester.painted_ops(tester.render_object(element))
9113        }
9114
9115        /// Dart's `expect(findBorderPainter(), paints…)`: what the border painter records.
9116        pub(super) fn border_painter_ops(tester: &WidgetTester) -> Vec<Op> {
9117            ops_of(
9118                tester,
9119                find_border_painter(tester).expect("a border painter"),
9120            )
9121        }
9122
9123        /// Dart's `expect(tester.renderObject(find.byType(InputDecorator)), paints…)`.
9124        pub(super) fn decorator_ops(tester: &WidgetTester) -> Vec<Op> {
9125            ops_of(tester, tester.element(find::by_type::<InputDecorator>()))
9126        }
9127
9128        /// Dart's `findBorderPainter()`: the `CustomPaint` the `_BorderContainer` builds, if any.
9129        pub(super) fn find_border_painter(tester: &WidgetTester) -> Option<AnyElement> {
9130            find::descendant(
9131                find::by_type::<BorderContainer>().first(),
9132                find::by_type::<CustomPaint>(),
9133            )
9134            .first()
9135            .evaluate(tester)
9136            .into_iter()
9137            .next()
9138        }
9139
9140        /// Reads the `_InputBorderPainter` of the border painter.
9141        pub(super) fn with_border_painter<R>(
9142            tester: &WidgetTester,
9143            read: impl FnOnce(&App, &InputBorderPainter) -> R,
9144        ) -> R {
9145            let element = find_border_painter(tester).expect("a border painter");
9146            let app = tester.cell.borrow();
9147            let custom_paint =
9148                downcast_widget::<CustomPaint>(&**element.widget(&app)).expect("a CustomPaint");
9149            let painter = custom_paint
9150                .foreground_painter
9151                .as_ref()
9152                .expect("a foreground painter");
9153            let painter = painter
9154                .as_any()
9155                .downcast_ref::<InputBorderPainter>()
9156                .expect("an _InputBorderPainter");
9157            read(&app, painter)
9158        }
9159
9160        /// Dart's `getBorder(tester)`: the border the painter paints now.
9161        pub(super) fn get_border(tester: &WidgetTester) -> Option<InputBorderRef> {
9162            find_border_painter(tester)?;
9163            Some(with_border_painter(tester, |app, painter| {
9164                painter
9165                    .border
9166                    .evaluate(app, painter.border_animation.handle())
9167            }))
9168        }
9169
9170        /// Dart's `getBorderSide(tester)`.
9171        pub(super) fn get_border_side(tester: &WidgetTester) -> BorderSide {
9172            get_border(tester).expect("a border").border_side()
9173        }
9174
9175        /// Dart's `getBorderRadius(tester)`.
9176        pub(super) fn get_border_radius(tester: &WidgetTester) -> Option<BorderRadius> {
9177            let border = get_border(tester).expect("a border");
9178            if let Some(underline) = border.as_any().downcast_ref::<UnderlineInputBorder>() {
9179                return Some(underline.border_radius);
9180            }
9181            border
9182                .as_any()
9183                .downcast_ref::<OutlineInputBorder>()
9184                .map(|outline| outline.border_radius)
9185        }
9186
9187        /// Dart's `getBorderWeight(tester)`.
9188        pub(super) fn get_border_weight(tester: &WidgetTester) -> f64 {
9189            get_border_side(tester).width
9190        }
9191
9192        /// Dart's `getBorderColor(tester)`.
9193        pub(super) fn get_border_color(tester: &WidgetTester) -> Color {
9194            get_border_side(tester).color
9195        }
9196
9197        /// The border each `_BorderContainer`'s `_InputBorderPainter` paints now and its
9198        /// `blendedColor`, in tree order: what Dart's tests read through the painter.
9199        pub(crate) fn borders_and_container_colors(
9200            tester: &WidgetTester,
9201        ) -> Vec<(InputBorderRef, Color)> {
9202            (0..find::by_type::<BorderContainer>().evaluate(tester).len())
9203                .filter_map(|index| {
9204                    find::descendant(
9205                        find::by_type::<BorderContainer>().at(index),
9206                        find::by_type::<CustomPaint>(),
9207                    )
9208                    .first()
9209                    .evaluate(tester)
9210                    .into_iter()
9211                    .next()
9212                })
9213                .map(|element| {
9214                    let app = tester.cell.borrow();
9215                    let custom_paint = downcast_widget::<CustomPaint>(&**element.widget(&app))
9216                        .expect("a CustomPaint");
9217                    let painter = custom_paint
9218                        .foreground_painter
9219                        .as_ref()
9220                        .and_then(|painter| painter.as_any().downcast_ref::<InputBorderPainter>())
9221                        .expect("an _InputBorderPainter");
9222                    (
9223                        painter
9224                            .border
9225                            .evaluate(&app, painter.border_animation.handle()),
9226                        painter.blended_color(&app),
9227                    )
9228                })
9229                .collect()
9230        }
9231
9232        /// Dart's `getContainerColor(tester)`: the painter's `blendedColor`.
9233        pub(super) fn get_container_color(tester: &WidgetTester) -> Color {
9234            with_border_painter(tester, |app, painter| painter.blended_color(app))
9235        }
9236
9237        /// Dart's `getBorderBottom(tester)` and `getContainerRect(tester).height`: the height of
9238        /// `InputDecorator.containerOf` the border painter.
9239        pub(super) fn get_border_bottom(tester: &WidgetTester) -> f64 {
9240            get_container_rect(tester).height()
9241        }
9242
9243        /// Dart's `getContainerRect(tester)`: the container's `paintBounds`.
9244        pub(super) fn get_container_rect(tester: &WidgetTester) -> Rect {
9245            let element = find_border_painter(tester).expect("a border painter");
9246            let app = tester.cell.borrow();
9247            let container: AnyRenderBox =
9248                InputDecorator::container_of(&app, element).expect("a decorator container");
9249            Offset::ZERO & container.size(&app)
9250        }
9251
9252        /// Dart's `findLabel()`: the label's text, a descendant of a `MatrixTransition` (the
9253        /// decorator's; the page route's transitions have their own).
9254        pub(super) fn find_label(tester: &WidgetTester) -> AnyElement {
9255            let transitions = find::by_type::<waft_widgets::Animated<MatrixTransition>>();
9256            for index in 0..transitions.evaluate(tester).len() {
9257                if let Some(text) = find::descendant(
9258                    transitions.clone().at(index),
9259                    find::by_type::<waft_widgets::Text>(),
9260                )
9261                .first()
9262                .evaluate(tester)
9263                .into_iter()
9264                .next()
9265                {
9266                    return text;
9267                }
9268            }
9269            panic!("no label")
9270        }
9271
9272        /// Dart's `getLabelRect(tester)`.
9273        pub(super) fn get_label_rect(tester: &WidgetTester) -> Rect {
9274            tester.get_rect(find_label(tester))
9275        }
9276
9277        /// Dart's `getLabelStyle(tester)`: the style of the `AnimatedDefaultTextStyle` above the label.
9278        pub(super) fn get_label_style(tester: &WidgetTester) -> TextStyle {
9279            let label = find_label(tester);
9280            let ancestor = tester
9281                .ancestors(label)
9282                .into_iter()
9283                .find(|element| {
9284                    let app = tester.cell.borrow();
9285                    downcast_widget::<waft_widgets::AnimatedDefaultTextStyle>(
9286                        &**element.widget(&app),
9287                    )
9288                    .is_some()
9289                })
9290                .expect("an AnimatedDefaultTextStyle above the label");
9291            tester.widget::<waft_widgets::AnimatedDefaultTextStyle, _>(ancestor, |style| {
9292                style.style.clone()
9293            })
9294        }
9295    }
9296    // The cases on the decoration and theme values.
9297    mod data {
9298        use waft_widgets::testing::test_widgets;
9299
9300        use waft_embedder::{Color, Radius};
9301        use waft_painting::{
9302            AnyColor, AnyTextStyle, BorderRadius, BorderSide, EdgeInsets, EdgeInsetsDirectional,
9303            EdgeInsetsGeometry, TextStyle,
9304        };
9305        use waft_rendering::BoxConstraints;
9306
9307        use super::super::*;
9308        use crate::colors::Colors;
9309        use crate::input_border::{InputBorderRef, OutlineInputBorder, UnderlineInputBorder};
9310        use crate::theme_data::ThemeData;
9311
9312        fn constraints(
9313            min_width: f64,
9314            max_width: f64,
9315            min_height: f64,
9316            max_height: f64,
9317        ) -> BoxConstraints {
9318            BoxConstraints::new()
9319                .min_width(min_width)
9320                .max_width(max_width)
9321                .min_height(min_height)
9322                .max_height(max_height)
9323        }
9324
9325        fn side(color: u32) -> BorderSide {
9326            BorderSide {
9327                color: Color::new(color),
9328                ..BorderSide::default()
9329            }
9330        }
9331
9332        fn border(border: impl Into<InputBorderRef>) -> Option<InputBorderRef> {
9333            Some(border.into())
9334        }
9335
9336        fn style(color: u32) -> Option<AnyTextStyle> {
9337            Some(TextStyle::new().color(Color::new(color)).into())
9338        }
9339
9340        fn color(color: u32) -> Option<AnyColor> {
9341            Some(Color::new(color).into())
9342        }
9343
9344        // input_decorator_test.dart 'InputDecorationThemeData.isCollapsed is applied'.
9345        #[test]
9346        fn a_theme_is_collapsed_is_applied() {
9347            let decoration = InputDecoration::new()
9348                .hint_text("Hello, Flutter!")
9349                .apply_defaults(InputDecorationThemeData::new().is_collapsed(true));
9350
9351            assert_eq!(decoration.is_collapsed, Some(true));
9352        }
9353
9354        // input_decorator_test.dart 'InputDecorationThemeData.isCollapsed defaults to false'.
9355        #[test]
9356        fn a_theme_is_collapsed_defaults_to_false() {
9357            let decoration = InputDecoration::new()
9358                .hint_text("Hello, Flutter!")
9359                .apply_defaults(InputDecorationThemeData::new());
9360
9361            assert_eq!(decoration.is_collapsed, Some(false));
9362        }
9363
9364        // input_decorator_test.dart 'InputDecorationThemeData.isCollapsed can be overridden'.
9365        #[test]
9366        fn a_theme_is_collapsed_can_be_overridden() {
9367            let decoration = InputDecoration::new()
9368                .is_collapsed(true)
9369                .hint_text("Hello, Flutter!")
9370                .apply_defaults(InputDecorationThemeData::new());
9371
9372            assert_eq!(decoration.is_collapsed, Some(true));
9373        }
9374
9375        // input_decorator_test.dart 'FloatingLabelAlignment.toString()'.
9376        #[test]
9377        fn floating_label_alignment_prints_its_name() {
9378            assert_eq!(
9379                format!("{:?}", FloatingLabelAlignment::START),
9380                "FloatingLabelAlignment.start"
9381            );
9382            assert_eq!(
9383                format!("{:?}", FloatingLabelAlignment::CENTER),
9384                "FloatingLabelAlignment.center"
9385            );
9386        }
9387
9388        // input_decorator_test.dart 'InputDecoration.applyDefaults initializes empty field'.
9389        #[test]
9390        fn apply_defaults_initializes_empty_fields() {
9391            let theme_style = style(0xFF00FFFF);
9392            let theme_color = Color::new(0xFF00FF00);
9393            let theme_input_border = OutlineInputBorder::new().border_side(side(0xFF0000FF));
9394
9395            let decoration = InputDecoration::new().apply_defaults(
9396                InputDecorationThemeData::new()
9397                    .label_style(theme_style.clone().unwrap())
9398                    .floating_label_style(theme_style.clone().unwrap())
9399                    .helper_style(theme_style.clone().unwrap())
9400                    .helper_max_lines(2)
9401                    .hint_style(theme_style.clone().unwrap())
9402                    .error_style(theme_style.clone().unwrap())
9403                    .error_max_lines(2)
9404                    .floating_label_behavior(FloatingLabelBehavior::Never)
9405                    .floating_label_alignment(FloatingLabelAlignment::CENTER)
9406                    .is_dense(true)
9407                    .content_padding(EdgeInsetsGeometry::all(1.0))
9408                    .icon_color(theme_color)
9409                    .prefix_style(theme_style.clone().unwrap())
9410                    .prefix_icon_color(theme_color)
9411                    .prefix_icon_constraints(constraints(10.0, 10.0, 30.0, 30.0))
9412                    .suffix_style(theme_style.clone().unwrap())
9413                    .suffix_icon_color(theme_color)
9414                    .suffix_icon_constraints(constraints(20.0, 20.0, 40.0, 40.0))
9415                    .counter_style(theme_style.clone().unwrap())
9416                    .filled(true)
9417                    .fill_color(theme_color)
9418                    .focus_color(theme_color)
9419                    .hover_color(theme_color)
9420                    .error_border(theme_input_border)
9421                    .focused_border(theme_input_border)
9422                    .focused_error_border(theme_input_border)
9423                    .disabled_border(theme_input_border)
9424                    .enabled_border(theme_input_border)
9425                    .border(InputBorderRef::none())
9426                    .align_label_with_hint(true)
9427                    .constraints(constraints(10.0, 20.0, 30.0, 40.0)),
9428            );
9429
9430            assert_eq!(decoration.label_style, theme_style);
9431            assert_eq!(decoration.floating_label_style, theme_style);
9432            assert_eq!(decoration.helper_style, theme_style);
9433            assert_eq!(decoration.helper_max_lines, Some(2));
9434            assert_eq!(decoration.hint_style, theme_style);
9435            assert_eq!(decoration.error_style, theme_style);
9436            assert_eq!(decoration.error_max_lines, Some(2));
9437            assert_eq!(
9438                decoration.floating_label_behavior,
9439                Some(FloatingLabelBehavior::Never)
9440            );
9441            assert_eq!(
9442                decoration.floating_label_alignment,
9443                Some(FloatingLabelAlignment::CENTER)
9444            );
9445            assert_eq!(decoration.is_dense, Some(true));
9446            assert_eq!(
9447                decoration.content_padding,
9448                Some(EdgeInsetsGeometry::all(1.0))
9449            );
9450            assert_eq!(decoration.icon_color, Some(theme_color.into()));
9451            assert_eq!(decoration.prefix_style, theme_style);
9452            assert_eq!(decoration.prefix_icon_color, Some(theme_color.into()));
9453            assert_eq!(
9454                decoration.prefix_icon_constraints,
9455                Some(constraints(10.0, 10.0, 30.0, 30.0))
9456            );
9457            assert_eq!(decoration.suffix_style, theme_style);
9458            assert_eq!(decoration.suffix_icon_color, Some(theme_color.into()));
9459            assert_eq!(
9460                decoration.suffix_icon_constraints,
9461                Some(constraints(20.0, 20.0, 40.0, 40.0))
9462            );
9463            assert_eq!(decoration.counter_style, theme_style);
9464            assert_eq!(decoration.filled, Some(true));
9465            assert_eq!(decoration.fill_color, Some(theme_color.into()));
9466            assert_eq!(decoration.focus_color, Some(theme_color));
9467            assert_eq!(decoration.hover_color, Some(theme_color));
9468            assert_eq!(decoration.error_border, border(theme_input_border));
9469            assert_eq!(decoration.focused_border, border(theme_input_border));
9470            assert_eq!(decoration.focused_error_border, border(theme_input_border));
9471            assert_eq!(decoration.disabled_border, border(theme_input_border));
9472            assert_eq!(decoration.enabled_border, border(theme_input_border));
9473            assert_eq!(decoration.border, Some(InputBorderRef::none()));
9474            assert_eq!(decoration.align_label_with_hint, Some(true));
9475            assert_eq!(
9476                decoration.constraints,
9477                Some(constraints(10.0, 20.0, 30.0, 40.0))
9478            );
9479        }
9480
9481        // input_decorator_test.dart 'InputDecoration.applyDefaults does not override non-null fields'.
9482        #[test]
9483        fn apply_defaults_does_not_override_non_null_fields() {
9484            let theme_style = style(0xFF00FFFF);
9485            let theme_color = Color::new(0xFF00FF00);
9486            let theme_input_border = OutlineInputBorder::new().border_side(side(0xFF0000FF));
9487            let decoration_style = style(0xFFFFFF00);
9488            let decoration_color = Color::new(0xFF0000FF);
9489            let decoration_input_border = OutlineInputBorder::new().border_side(side(0xFFFF00FF));
9490            let decoration_constraints = constraints(40.0, 50.0, 60.0, 70.0);
9491
9492            let decoration = InputDecoration::new()
9493                .label_style(decoration_style.clone().unwrap())
9494                .floating_label_style(decoration_style.clone().unwrap())
9495                .helper_style(decoration_style.clone().unwrap())
9496                .helper_max_lines(3)
9497                .hint_style(decoration_style.clone().unwrap())
9498                .error_style(decoration_style.clone().unwrap())
9499                .error_max_lines(3)
9500                .floating_label_behavior(FloatingLabelBehavior::Always)
9501                .floating_label_alignment(FloatingLabelAlignment::START)
9502                .is_dense(false)
9503                .content_padding(EdgeInsetsGeometry::all(4.0))
9504                .icon_color(decoration_color)
9505                .prefix_style(decoration_style.clone().unwrap())
9506                .prefix_icon_color(decoration_color)
9507                .prefix_icon_constraints(decoration_constraints)
9508                .suffix_style(decoration_style.clone().unwrap())
9509                .suffix_icon_color(decoration_color)
9510                .suffix_icon_constraints(decoration_constraints)
9511                .counter_style(decoration_style.clone().unwrap())
9512                .filled(false)
9513                .fill_color(decoration_color)
9514                .focus_color(decoration_color)
9515                .hover_color(decoration_color)
9516                .error_border(decoration_input_border)
9517                .focused_border(decoration_input_border)
9518                .focused_error_border(decoration_input_border)
9519                .disabled_border(decoration_input_border)
9520                .enabled_border(decoration_input_border)
9521                .border(OutlineInputBorder::new())
9522                .align_label_with_hint(false)
9523                .constraints(decoration_constraints)
9524                .apply_defaults(
9525                    InputDecorationThemeData::new()
9526                        .label_style(theme_style.clone().unwrap())
9527                        .floating_label_style(theme_style.clone().unwrap())
9528                        .helper_style(theme_style.clone().unwrap())
9529                        .helper_max_lines(2)
9530                        .hint_style(theme_style.clone().unwrap())
9531                        .error_style(theme_style.clone().unwrap())
9532                        .error_max_lines(2)
9533                        .floating_label_behavior(FloatingLabelBehavior::Never)
9534                        .floating_label_alignment(FloatingLabelAlignment::CENTER)
9535                        .is_dense(true)
9536                        .content_padding(EdgeInsetsGeometry::all(1.0))
9537                        .icon_color(theme_color)
9538                        .prefix_style(theme_style.clone().unwrap())
9539                        .prefix_icon_color(theme_color)
9540                        .suffix_style(theme_style.clone().unwrap())
9541                        .suffix_icon_color(theme_color)
9542                        .counter_style(theme_style.clone().unwrap())
9543                        .filled(true)
9544                        .fill_color(theme_color)
9545                        .focus_color(theme_color)
9546                        .hover_color(theme_color)
9547                        .error_border(theme_input_border)
9548                        .focused_border(theme_input_border)
9549                        .focused_error_border(theme_input_border)
9550                        .disabled_border(theme_input_border)
9551                        .enabled_border(theme_input_border)
9552                        .border(InputBorderRef::none())
9553                        .align_label_with_hint(true)
9554                        .constraints(constraints(10.0, 20.0, 30.0, 40.0)),
9555                );
9556
9557            assert_eq!(decoration.label_style, decoration_style);
9558            assert_eq!(decoration.floating_label_style, decoration_style);
9559            assert_eq!(decoration.helper_style, decoration_style);
9560            assert_eq!(decoration.helper_max_lines, Some(3));
9561            assert_eq!(decoration.hint_style, decoration_style);
9562            assert_eq!(decoration.error_style, decoration_style);
9563            assert_eq!(decoration.error_max_lines, Some(3));
9564            assert_eq!(
9565                decoration.floating_label_behavior,
9566                Some(FloatingLabelBehavior::Always)
9567            );
9568            assert_eq!(
9569                decoration.floating_label_alignment,
9570                Some(FloatingLabelAlignment::START)
9571            );
9572            assert_eq!(decoration.is_dense, Some(false));
9573            assert_eq!(
9574                decoration.content_padding,
9575                Some(EdgeInsetsGeometry::all(4.0))
9576            );
9577            assert_eq!(decoration.icon_color, Some(decoration_color.into()));
9578            assert_eq!(decoration.prefix_style, decoration_style);
9579            assert_eq!(decoration.prefix_icon_color, Some(decoration_color.into()));
9580            assert_eq!(
9581                decoration.prefix_icon_constraints,
9582                Some(decoration_constraints)
9583            );
9584            assert_eq!(decoration.suffix_style, decoration_style);
9585            assert_eq!(decoration.suffix_icon_color, Some(decoration_color.into()));
9586            assert_eq!(
9587                decoration.suffix_icon_constraints,
9588                Some(decoration_constraints)
9589            );
9590            assert_eq!(decoration.counter_style, decoration_style);
9591            assert_eq!(decoration.filled, Some(false));
9592            assert_eq!(decoration.fill_color, Some(decoration_color.into()));
9593            assert_eq!(decoration.focus_color, Some(decoration_color));
9594            assert_eq!(decoration.hover_color, Some(decoration_color));
9595            assert_eq!(decoration.error_border, border(decoration_input_border));
9596            assert_eq!(decoration.focused_border, border(decoration_input_border));
9597            assert_eq!(
9598                decoration.focused_error_border,
9599                border(decoration_input_border)
9600            );
9601            assert_eq!(decoration.disabled_border, border(decoration_input_border));
9602            assert_eq!(decoration.enabled_border, border(decoration_input_border));
9603            assert_eq!(decoration.border, border(OutlineInputBorder::new()));
9604            assert_eq!(decoration.align_label_with_hint, Some(false));
9605            assert_eq!(decoration.constraints, Some(decoration_constraints));
9606        }
9607
9608        // input_decorator_test.dart 'InputDecoration.applyDefaults accepts only a InputDecorationTheme
9609        // or a InputDecorationThemeData': the two accepted types (the third, an `Object`, does not
9610        // compile here).
9611        #[test]
9612        fn apply_defaults_accepts_a_theme_or_its_data() {
9613            let decoration = InputDecoration::new();
9614            assert_eq!(
9615                decoration.apply_defaults(InputDecorationTheme::new()),
9616                decoration.apply_defaults(InputDecorationThemeData::new())
9617            );
9618        }
9619
9620        // input_decorator_test.dart 'InputDecorationThemeData.toString()', without the `labelStyle`
9621        // spot check: a `TextStyle` prints its fields in Rust's `Debug` form, not Dart's
9622        // `TextStyle(inherit: true, height: 1.0x)`.
9623        #[test]
9624        fn theme_data_prints_its_non_default_properties() {
9625            assert!(
9626                format!(
9627                    "{:?}",
9628                    InputDecorationThemeData::new()
9629                        .content_padding(EdgeInsetsDirectional::only(5.0, 0.0, 0.0, 0.0))
9630                )
9631                .contains("contentPadding: EdgeInsetsDirectional(5.0, 0.0, 0.0, 0.0)")
9632            );
9633
9634            assert!(
9635                format!(
9636                    "{:?}",
9637                    InputDecorationThemeData::new()
9638                        .content_padding(EdgeInsets::only(5.0, 0.0, 0.0, 0.0))
9639                )
9640                .contains("contentPadding: EdgeInsets(5.0, 0.0, 0.0, 0.0)")
9641            );
9642
9643            let debug_string = format!(
9644                "{:?}",
9645                InputDecorationThemeData::new()
9646                    .label_style(TextStyle::new().height(1.0))
9647                    .helper_style(TextStyle::new().height(2.0))
9648                    .helper_max_lines(5)
9649                    .hint_style(TextStyle::new().height(3.0))
9650                    .error_style(TextStyle::new().height(4.0))
9651                    .error_max_lines(5)
9652                    .is_dense(true)
9653                    .content_padding(EdgeInsets::only(0.0, 0.0, 6.0, 0.0))
9654                    .is_collapsed(true)
9655                    .prefix_style(TextStyle::new().height(7.0))
9656                    .suffix_style(TextStyle::new().height(8.0))
9657                    .counter_style(TextStyle::new().height(9.0))
9658                    .filled(true)
9659                    .fill_color(Color::new(0x00000010))
9660                    .focus_color(Color::new(0x00000020))
9661                    .error_border(UnderlineInputBorder::new())
9662                    .focused_border(OutlineInputBorder::new())
9663                    .focused_error_border(UnderlineInputBorder::new())
9664                    .disabled_border(OutlineInputBorder::new())
9665                    .enabled_border(UnderlineInputBorder::new())
9666                    .border(OutlineInputBorder::new())
9667            );
9668
9669            assert!(debug_string.contains("isDense: true"));
9670            assert!(debug_string.contains(&format!("fillColor: {:?}", Color::new(0x00000010))));
9671            assert!(debug_string.contains(&format!("focusColor: {:?}", Color::new(0x00000020))));
9672            assert!(debug_string.contains("errorBorder: UnderlineInputBorder()"));
9673            assert!(debug_string.contains("focusedBorder: OutlineInputBorder()"));
9674        }
9675
9676        // input_decorator_test.dart 'InputDecorationThemeData.copyWith keeps original iconColor'.
9677        #[test]
9678        fn theme_data_copy_with_keeps_the_original_icon_color() {
9679            let original = InputDecorationThemeData::new().icon_color(Color::new(0xDEADBEEF));
9680            assert_eq!(original.icon_color, color(0xDEADBEEF));
9681            assert_ne!(original.fill_color, color(0xDEADCAFE));
9682            let copy1 = original.copy_with().fill_color(Color::new(0xDEADCAFE));
9683            assert_eq!(copy1.icon_color, color(0xDEADBEEF));
9684            assert_eq!(copy1.fill_color, color(0xDEADCAFE));
9685            let copy2 = original.copy_with().icon_color(Color::new(0xDEADCAFE));
9686            assert_eq!(copy2.icon_color, color(0xDEADCAFE));
9687            assert_ne!(copy2.fill_color, color(0xDEADCAFE));
9688        }
9689
9690        // input_decorator_test.dart 'InputDecorationThemeData copyWith, ==, hashCode basics', without
9691        // the `hashCode` half (deferred).
9692        #[test]
9693        fn theme_data_equals_its_copy() {
9694            assert_eq!(
9695                InputDecorationThemeData::new(),
9696                InputDecorationThemeData::new().copy_with()
9697            );
9698        }
9699
9700        // input_decorator_test.dart 'InputDecorationThemeData copyWith correctly copies and replaces
9701        // values'.
9702        #[test]
9703        fn theme_data_copy_with_copies_and_replaces_values() {
9704            let original = InputDecorationThemeData::new()
9705                .focus_color(Colors::ORANGE.primary())
9706                .fill_color(Colors::GREEN.primary());
9707            let copy = original
9708                .copy_with()
9709                .focus_color(Colors::YELLOW.primary())
9710                .fill_color(Colors::BLUE.primary());
9711
9712            assert_eq!(original.focus_color, Some(Colors::ORANGE.primary()));
9713            assert_eq!(original.fill_color, Some(Colors::GREEN.primary().into()));
9714            assert_eq!(copy.focus_color, Some(Colors::YELLOW.primary()));
9715            assert_eq!(copy.fill_color, Some(Colors::BLUE.primary().into()));
9716        }
9717
9718        // input_decorator_test.dart 'InputDecorationThemeData merge'.
9719        #[test]
9720        fn theme_data_merge_fills_only_the_nullable_fields() {
9721            test_widgets(|tester| {
9722                let app = tester.cell.borrow();
9723                let override_theme = InputDecorationThemeData::new()
9724                    .label_style(TextStyle::new().color(Color::new(0x000000f0)))
9725                    .floating_label_style(TextStyle::new().color(Color::new(0x000000f1)))
9726                    .helper_style(TextStyle::new().color(Color::new(0x000000f2)))
9727                    .helper_max_lines(1)
9728                    .hint_style(TextStyle::new().color(Color::new(0x000000f3)))
9729                    .error_style(TextStyle::new().color(Color::new(0x000000f4)))
9730                    .error_max_lines(1)
9731                    .floating_label_behavior(FloatingLabelBehavior::Never)
9732                    .floating_label_alignment(FloatingLabelAlignment::CENTER)
9733                    .is_dense(true)
9734                    .content_padding(EdgeInsetsGeometry::all(1.0))
9735                    .is_collapsed(true)
9736                    .icon_color(Color::new(0x000000f5))
9737                    .prefix_style(TextStyle::new().color(Color::new(0x000000f6)))
9738                    .prefix_icon_color(Color::new(0x000000f7))
9739                    .suffix_style(TextStyle::new().color(Color::new(0x000000f8)))
9740                    .suffix_icon_color(Color::new(0x000000f9))
9741                    .counter_style(TextStyle::new().color(Color::new(0x00000f10)))
9742                    .filled(true)
9743                    .fill_color(Color::new(0x00000f11))
9744                    .active_indicator_border(side(0x00000f12))
9745                    .outline_border(side(0x00000f13))
9746                    .focus_color(Color::new(0x00000f14))
9747                    .hover_color(Color::new(0x00000f15))
9748                    .error_border(
9749                        OutlineInputBorder::new()
9750                            .border_radius(BorderRadius::all(Radius::circular(2.0))),
9751                    )
9752                    .focused_border(OutlineInputBorder::new().border_side(side(0x00000f16)))
9753                    .focused_error_border(OutlineInputBorder::new().border_side(side(0x00000f17)))
9754                    .disabled_border(OutlineInputBorder::new().border_side(side(0x00000f18)))
9755                    .enabled_border(OutlineInputBorder::new().border_side(side(0x00000f19)))
9756                    .border(OutlineInputBorder::new().border_side(side(0x00000f20)))
9757                    .align_label_with_hint(true)
9758                    .constraints(BoxConstraints::new().min_height(1.0).min_width(1.0));
9759
9760                let input_decoration_theme = ThemeData::new(&app).input_decoration_theme;
9761                let merged = input_decoration_theme.merge(Some(&override_theme));
9762
9763                assert_eq!(merged.label_style, override_theme.label_style);
9764                assert_eq!(
9765                    merged.floating_label_style,
9766                    override_theme.floating_label_style
9767                );
9768                assert_eq!(merged.helper_style, override_theme.helper_style);
9769                assert_eq!(merged.helper_max_lines, override_theme.helper_max_lines);
9770                assert_eq!(merged.hint_style, override_theme.hint_style);
9771                assert_eq!(merged.error_style, override_theme.error_style);
9772                assert_eq!(merged.error_max_lines, override_theme.error_max_lines);
9773                assert_ne!(
9774                    merged.floating_label_behavior,
9775                    override_theme.floating_label_behavior
9776                );
9777                assert_ne!(
9778                    merged.floating_label_alignment,
9779                    override_theme.floating_label_alignment
9780                );
9781                assert_ne!(merged.is_dense, override_theme.is_dense);
9782                assert_eq!(merged.content_padding, override_theme.content_padding);
9783                assert_ne!(merged.is_collapsed, override_theme.is_collapsed);
9784                assert_eq!(merged.icon_color, override_theme.icon_color);
9785                assert_eq!(merged.prefix_style, override_theme.prefix_style);
9786                assert_eq!(merged.prefix_icon_color, override_theme.prefix_icon_color);
9787                assert_eq!(merged.suffix_style, override_theme.suffix_style);
9788                assert_eq!(merged.suffix_icon_color, override_theme.suffix_icon_color);
9789                assert_eq!(merged.counter_style, override_theme.counter_style);
9790                assert_ne!(merged.filled, override_theme.filled);
9791                assert_eq!(merged.fill_color, override_theme.fill_color);
9792                assert_eq!(
9793                    merged.active_indicator_border,
9794                    override_theme.active_indicator_border
9795                );
9796                assert_eq!(merged.outline_border, override_theme.outline_border);
9797                assert_eq!(merged.focus_color, override_theme.focus_color);
9798                assert_eq!(merged.hover_color, override_theme.hover_color);
9799                assert_eq!(merged.error_border, override_theme.error_border);
9800                assert_eq!(merged.focused_border, override_theme.focused_border);
9801                assert_eq!(
9802                    merged.focused_error_border,
9803                    override_theme.focused_error_border
9804                );
9805                assert_eq!(merged.disabled_border, override_theme.disabled_border);
9806                assert_eq!(merged.enabled_border, override_theme.enabled_border);
9807                assert_eq!(merged.border, override_theme.border);
9808                assert_ne!(
9809                    merged.align_label_with_hint,
9810                    override_theme.align_label_with_hint
9811                );
9812                assert_eq!(merged.constraints, override_theme.constraints);
9813            });
9814        }
9815
9816        // The data `InputDecorationTheme` builds from its properties takes Dart's defaults, and a
9817        // theme given a `data` answers it: Dart's getters and `data`.
9818        #[test]
9819        fn a_theme_widget_answers_its_properties_or_its_data() {
9820            let theme = InputDecorationTheme::new().with_is_dense(true);
9821            let data = theme.data();
9822            assert!(data.is_dense);
9823            assert_eq!(data.floating_label_behavior, FloatingLabelBehavior::Auto);
9824            assert_eq!(data.floating_label_alignment, FloatingLabelAlignment::START);
9825            assert!(!data.filled);
9826
9827            let given = InputDecorationThemeData::new().hint_max_lines(3);
9828            let theme = InputDecorationTheme::new().with_data(given.clone());
9829            assert_eq!(theme.hint_max_lines(), Some(3));
9830            assert_eq!(theme.data(), given);
9831        }
9832
9833        // The six cross-field asserts of Dart's `InputDecoration` constructor.
9834        #[test]
9835        #[should_panic(expected = "Declaring both hint and hintText is not supported.")]
9836        fn a_decoration_with_both_hint_and_hint_text_fails_its_check() {
9837            InputDecoration::new()
9838                .hint_text("hint")
9839                .hint(Text::new("hint"))
9840                .debug_check_arguments();
9841        }
9842
9843        // InputDecoration `==` compares its widgets by identity, as Dart's widget `==` does.
9844        #[test]
9845        fn decorations_compare_widgets_by_identity_and_values_by_value() {
9846            let icon: WidgetRef = SizedBox::shrink().into_widget();
9847            let a = InputDecoration::new()
9848                .icon(icon.clone())
9849                .label_text("label");
9850            assert_eq!(a, a.copy_with());
9851            assert_eq!(a, InputDecoration::new().icon(icon).label_text("label"));
9852            assert_ne!(
9853                a,
9854                InputDecoration::new()
9855                    .icon(SizedBox::shrink())
9856                    .label_text("label")
9857            );
9858        }
9859
9860        // Dart's `toString` lists the set fields with its quoting.
9861        #[test]
9862        fn a_decoration_prints_its_set_fields() {
9863            assert_eq!(
9864                format!(
9865                    "{:?}",
9866                    InputDecoration::new()
9867                        .label_text("label")
9868                        .helper_max_lines(2)
9869                        .enabled(false)
9870                ),
9871                "InputDecoration(labelText: \"label\", helperMaxLines: \"2\", enabled: false)"
9872            );
9873            assert_eq!(
9874                format!("{:?}", InputDecoration::collapsed(Some("hint".to_owned()))),
9875                "InputDecoration(hintText: \"hint\", contentPadding: EdgeInsets.zero, \
9876             isCollapsed: true, border: _NoInputBorder(), alignLabelWithHint: false)"
9877            );
9878        }
9879    }
9880
9881    // input_decorator_test.dart's 'Material3 - InputDecoration container' group and the input
9882    // border cases after it.
9883    #[allow(deprecated)]
9884    mod container_and_borders {
9885        use waft_widgets::testing::{
9886            TargetPlatformVariant, WidgetTester, test_widgets, test_widgets_variant,
9887        };
9888
9889        use waft_embedder::valo::Op;
9890        use waft_embedder::{Canvas, Color, Offset, RRect, Radius, Rect, TargetPlatform};
9891        use waft_painting::{
9892            Alignment, AlignmentGeometry, BorderRadius, BorderSide, EdgeInsetsGeometry,
9893            ShapeBorder, TextDirection,
9894        };
9895        use waft_widgets::{Container, Icon, IntoWidget, RepaintBoundary, WidgetRef};
9896
9897        use super::super::*;
9898        use super::common::K_TRANSITION_DURATION;
9899        use super::common::*;
9900        use crate::app::MaterialApp;
9901        use crate::colors::Colors;
9902        use crate::icons::Icons;
9903        use crate::input_border::{InputBorderRef, OutlineInputBorder, UnderlineInputBorder};
9904        use crate::scaffold::Scaffold;
9905        use crate::theme::Theme;
9906        use crate::theme_data::{ThemeData, VisualDensity};
9907
9908        // Default container height for InputDecorator (filled or outlined) is 56dp on mobile
9909        // whether the label is floating or not.
9910        // This value is taken from https://m3.material.io/components/text-fields/specs.
9911        const CONTAINER_HEIGHT: f64 = 56.0;
9912
9913        // On desktop, visual density is used to reduce the container height.
9914        // Desktop default density is [VisualDensity.compact] which corresponds to a density value of -2.
9915        // As a rule of thumb, a change of 1 or -1 in density corresponds to 4 logical pixels.
9916        // See https://m3.material.io/foundations/layout/understanding-layout/spacing#a5674a8b-5f38-4a58-8202-5838b082390d.
9917        const DESKTOP_CONTAINER_HEIGHT: f64 = CONTAINER_HEIGHT - 2.0 * 4.0; // 48.0
9918
9919        /// Dart's `TargetPlatformVariant.all()`.
9920        const ALL_PLATFORMS: [TargetPlatform; 6] = [
9921            TargetPlatform::Android,
9922            TargetPlatform::Fuchsia,
9923            TargetPlatform::IOS,
9924            TargetPlatform::Linux,
9925            TargetPlatform::MacOS,
9926            TargetPlatform::Windows,
9927        ];
9928
9929        /// Dart's `TargetPlatformVariant.desktop()`.
9930        const DESKTOP_PLATFORMS: [TargetPlatform; 3] = [
9931            TargetPlatform::Linux,
9932            TargetPlatform::MacOS,
9933            TargetPlatform::Windows,
9934        ];
9935
9936        fn pump(tester: &mut WidgetTester, decorator: BuildInputDecorator) {
9937            tester.pump_widget(decorator.build());
9938        }
9939
9940        /// Dart's `Theme.of(tester.element(findDecorator()))`.
9941        fn theme_of(tester: &WidgetTester) -> Rc<ThemeData> {
9942            let element = tester.element(find::by_type::<InputDecorator>());
9943            Theme::of(&mut tester.cell.borrow_mut(), element)
9944        }
9945
9946        /// The decoration of the filled cases: `filled`, `labelText` and `helperText` (or
9947        /// `errorText` when `error`).
9948        fn filled(error: bool) -> InputDecoration {
9949            let decoration = InputDecoration::new().filled(true).label_text(LABEL_TEXT);
9950            if error {
9951                decoration.error_text(ERROR_TEXT)
9952            } else {
9953                decoration.helper_text(HELPER_TEXT)
9954            }
9955        }
9956
9957        /// The decoration of the outlined cases: `OutlineInputBorder()`, `labelText` and
9958        /// `helperText` (or `errorText` when `error`).
9959        fn outlined(error: bool) -> InputDecoration {
9960            let decoration = InputDecoration::new()
9961                .border(OutlineInputBorder::new())
9962                .label_text(LABEL_TEXT);
9963            if error {
9964                decoration.error_text(ERROR_TEXT)
9965            } else {
9966                decoration.helper_text(HELPER_TEXT)
9967            }
9968        }
9969
9970        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
9971        // - when field is enabled - container has correct height and shape'.
9972        #[test]
9973        fn a_filled_enabled_container_has_the_m3_height_and_an_underline_with_rounded_top() {
9974            test_widgets(|tester| {
9975                check_filled_shape(tester, BuildInputDecorator::new(filled(false)));
9976            });
9977        }
9978
9979        fn check_filled_shape(tester: &mut WidgetTester, decorator: BuildInputDecorator) {
9980            pump(tester, decorator);
9981            assert_eq!(get_container_rect(tester).height(), CONTAINER_HEIGHT);
9982            assert!(
9983                get_border(tester)
9984                    .expect("a border")
9985                    .as_any()
9986                    .is::<UnderlineInputBorder>()
9987            );
9988            assert_eq!(
9989                get_border_radius(tester),
9990                Some(BorderRadius::only(
9991                    Radius::circular(4.0),
9992                    Radius::circular(4.0),
9993                    Radius::ZERO,
9994                    Radius::ZERO,
9995                ))
9996            );
9997        }
9998
9999        fn check_outlined_shape(tester: &mut WidgetTester, decorator: BuildInputDecorator) {
10000            pump(tester, decorator);
10001            assert_eq!(get_container_rect(tester).height(), CONTAINER_HEIGHT);
10002            assert!(
10003                get_border(tester)
10004                    .expect("a border")
10005                    .as_any()
10006                    .is::<OutlineInputBorder>()
10007            );
10008            assert_eq!(
10009                get_border_radius(tester),
10010                Some(BorderRadius::all(Radius::circular(4.0)))
10011            );
10012        }
10013
10014        /// Dart's `expect(findBorderPainter(), paints..rrect(style: fill, color: color))`.
10015        fn check_filled_color(
10016            tester: &mut WidgetTester,
10017            decorator: BuildInputDecorator,
10018            color: fn(&ThemeData) -> Color,
10019        ) {
10020            pump(tester, decorator);
10021            let color = color(&theme_of(tester));
10022            assert_paints(
10023                &border_painter_ops(tester),
10024                &[PaintCall::RRect {
10025                    rrect: None,
10026                    color: Some(color),
10027                    style: Some(PaintedStyle::Fill),
10028                    has_mask_filter: None,
10029                }],
10030            );
10031        }
10032
10033        /// Dart's `expect(findBorderPainter(), paints..path(style: PaintingStyle.stroke))`.
10034        fn check_outlined_painted(tester: &mut WidgetTester, decorator: BuildInputDecorator) {
10035            pump(tester, decorator);
10036            assert_paints(
10037                &border_painter_ops(tester),
10038                &[PaintCall::Path {
10039                    color: None,
10040                    style: Some(PaintedStyle::Stroke(None)),
10041                    includes: Vec::new(),
10042                    excludes: Vec::new(),
10043                }],
10044            );
10045        }
10046
10047        fn check_border(
10048            tester: &mut WidgetTester,
10049            decorator: BuildInputDecorator,
10050            color: fn(&ThemeData) -> Color,
10051            width: f64,
10052        ) {
10053            pump(tester, decorator);
10054            let color = color(&theme_of(tester));
10055            assert_eq!(get_border_color(tester), color);
10056            assert_eq!(get_border_weight(tester), width);
10057        }
10058
10059        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10060        // - when field is enabled - container has correct color'.
10061        #[test]
10062        fn a_filled_enabled_container_is_filled_with_surface_container_highest() {
10063            test_widgets(|tester| {
10064                check_filled_color(tester, BuildInputDecorator::new(filled(false)), |theme| {
10065                    theme.color_scheme.surface_container_highest()
10066                });
10067            });
10068        }
10069
10070        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10071        // - when field is enabled - active indicator has correct weight and color'.
10072        #[test]
10073        fn a_filled_enabled_active_indicator_is_on_surface_variant_and_1_wide() {
10074            test_widgets(|tester| {
10075                check_border(
10076                    tester,
10077                    BuildInputDecorator::new(filled(false)),
10078                    |theme| theme.color_scheme.on_surface_variant(),
10079                    1.0,
10080                );
10081            });
10082        }
10083
10084        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10085        // - when field is disabled - container has correct height and shape'.
10086        #[test]
10087        fn a_filled_disabled_container_has_the_m3_height_and_an_underline_with_rounded_top() {
10088            test_widgets(|tester| {
10089                check_filled_shape(
10090                    tester,
10091                    BuildInputDecorator::new(filled(false).enabled(false)),
10092                );
10093            });
10094        }
10095
10096        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10097        // - when field is disabled - container has correct color'.
10098        #[test]
10099        fn a_filled_disabled_container_is_filled_with_4_percent_on_surface() {
10100            test_widgets(|tester| {
10101                check_filled_color(
10102                    tester,
10103                    BuildInputDecorator::new(filled(false).enabled(false)),
10104                    |theme| theme.color_scheme.on_surface().with_opacity(0.04),
10105                );
10106            });
10107        }
10108
10109        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10110        // - when field is disabled - active indicator has correct weight and color'.
10111        #[test]
10112        fn a_filled_disabled_active_indicator_is_38_percent_on_surface_and_1_wide() {
10113            test_widgets(|tester| {
10114                check_border(
10115                    tester,
10116                    BuildInputDecorator::new(filled(false).enabled(false)),
10117                    |theme| theme.color_scheme.on_surface().with_opacity(0.38),
10118                    1.0,
10119                );
10120            });
10121        }
10122
10123        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10124        // - when field is hovered - container has correct height and shape'.
10125        #[test]
10126        fn a_filled_hovered_container_has_the_m3_height_and_an_underline_with_rounded_top() {
10127            test_widgets(|tester| {
10128                check_filled_shape(
10129                    tester,
10130                    BuildInputDecorator::new(filled(false)).is_hovering(true),
10131                );
10132            });
10133        }
10134
10135        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10136        // - when field is hovered - container has correct color'.
10137        #[test]
10138        fn a_filled_hovered_container_blends_the_hover_color_over_surface_container_highest() {
10139            test_widgets(|tester| {
10140                pump(
10141                    tester,
10142                    BuildInputDecorator::new(filled(false)).is_hovering(true),
10143                );
10144                let theme = theme_of(tester);
10145                assert_eq!(theme.hover_color, Colors::BLACK.with_opacity(0.04));
10146                assert_paints(
10147                    &border_painter_ops(tester),
10148                    &[PaintCall::RRect {
10149                        rrect: None,
10150                        color: Some(Color::alpha_blend(
10151                            theme.hover_color,
10152                            theme.color_scheme.surface_container_highest(),
10153                        )),
10154                        style: Some(PaintedStyle::Fill),
10155                        has_mask_filter: None,
10156                    }],
10157                );
10158            });
10159        }
10160
10161        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10162        // - when field is hovered - active indicator has correct weight and color'.
10163        #[test]
10164        fn a_filled_hovered_active_indicator_is_on_surface_and_1_wide() {
10165            test_widgets(|tester| {
10166                check_border(
10167                    tester,
10168                    BuildInputDecorator::new(filled(false)).is_hovering(true),
10169                    |theme| theme.color_scheme.on_surface(),
10170                    1.0,
10171                );
10172            });
10173        }
10174
10175        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10176        // - when field is focused - container has correct height and shape'.
10177        #[test]
10178        fn a_filled_focused_container_has_the_m3_height_and_an_underline_with_rounded_top() {
10179            test_widgets(|tester| {
10180                check_filled_shape(
10181                    tester,
10182                    BuildInputDecorator::new(filled(false)).is_focused(true),
10183                );
10184            });
10185        }
10186
10187        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10188        // - when field is focused - container has correct color'.
10189        #[test]
10190        fn a_filled_focused_container_is_filled_with_surface_container_highest() {
10191            test_widgets(|tester| {
10192                check_filled_color(
10193                    tester,
10194                    BuildInputDecorator::new(filled(false)).is_focused(true),
10195                    |theme| theme.color_scheme.surface_container_highest(),
10196                );
10197            });
10198        }
10199
10200        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10201        // - when field is focused - container has correct color when focused and hovered'.
10202        #[test]
10203        fn a_filled_focused_and_hovered_container_blends_the_hover_color_over_the_fill() {
10204            test_widgets(|tester| {
10205                check_filled_color(
10206                    tester,
10207                    BuildInputDecorator::new(filled(false))
10208                        .is_focused(true)
10209                        .is_hovering(true),
10210                    |theme| {
10211                        let focus_color = theme.color_scheme.surface_container_highest();
10212                        let hover_color = theme.hover_color;
10213                        Color::alpha_blend(hover_color, focus_color)
10214                    },
10215                );
10216            });
10217        }
10218
10219        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10220        // - when field is focused - active indicator has correct weight and color'.
10221        #[test]
10222        fn a_filled_focused_active_indicator_is_primary_and_2_wide() {
10223            test_widgets(|tester| {
10224                check_border(
10225                    tester,
10226                    BuildInputDecorator::new(filled(false)).is_focused(true),
10227                    |theme| theme.color_scheme.primary(),
10228                    2.0,
10229                );
10230            });
10231        }
10232
10233        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10234        // - when field is focused - active indicator has correct weight and color when focused and
10235        // hovered'.
10236        #[test]
10237        fn a_filled_focused_and_hovered_active_indicator_is_primary_and_2_wide() {
10238            test_widgets(|tester| {
10239                check_border(
10240                    tester,
10241                    BuildInputDecorator::new(filled(false))
10242                        .is_focused(true)
10243                        .is_hovering(true),
10244                    |theme| theme.color_scheme.primary(),
10245                    2.0,
10246                );
10247            });
10248        }
10249
10250        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10251        // - when field is in error - container has correct height and shape'.
10252        #[test]
10253        fn a_filled_error_container_has_the_m3_height_and_an_underline_with_rounded_top() {
10254            test_widgets(|tester| {
10255                check_filled_shape(tester, BuildInputDecorator::new(filled(true)));
10256            });
10257        }
10258
10259        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10260        // - when field is in error - container has correct color'.
10261        #[test]
10262        fn a_filled_error_container_is_filled_with_surface_container_highest() {
10263            test_widgets(|tester| {
10264                check_filled_color(tester, BuildInputDecorator::new(filled(true)), |theme| {
10265                    theme.color_scheme.surface_container_highest()
10266                });
10267            });
10268        }
10269
10270        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10271        // - when field is in error - active indicator has correct weight and color'.
10272        #[test]
10273        fn a_filled_error_active_indicator_is_error_and_1_wide() {
10274            test_widgets(|tester| {
10275                check_border(
10276                    tester,
10277                    BuildInputDecorator::new(filled(true)),
10278                    |theme| theme.color_scheme.error(),
10279                    1.0,
10280                );
10281            });
10282        }
10283
10284        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10285        // - when field is in error - active indicator has correct weight and color when focused'.
10286        #[test]
10287        fn a_filled_focused_error_active_indicator_is_error_and_2_wide() {
10288            test_widgets(|tester| {
10289                check_border(
10290                    tester,
10291                    BuildInputDecorator::new(filled(true)).is_focused(true),
10292                    |theme| theme.color_scheme.error(),
10293                    2.0,
10294                );
10295            });
10296        }
10297
10298        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10299        // - when field is in error - active indicator has correct weight and color when hovered'.
10300        #[test]
10301        fn a_filled_hovered_error_active_indicator_is_on_error_container_and_1_wide() {
10302            test_widgets(|tester| {
10303                check_border(
10304                    tester,
10305                    BuildInputDecorator::new(filled(true)).is_hovering(true),
10306                    |theme| theme.color_scheme.on_error_container(),
10307                    1.0,
10308                );
10309            });
10310        }
10311
10312        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10313        // - when field is in error - active indicator has correct weight and color when focused and
10314        // hovered'.
10315        #[test]
10316        fn a_filled_focused_and_hovered_error_active_indicator_is_error_and_2_wide() {
10317            test_widgets(|tester| {
10318                check_border(
10319                    tester,
10320                    BuildInputDecorator::new(filled(true))
10321                        .is_focused(true)
10322                        .is_hovering(true),
10323                    |theme| theme.color_scheme.error(),
10324                    2.0,
10325                );
10326            });
10327        }
10328
10329        /// Pumps `decoration` on each of `platforms` and checks the container's height.
10330        fn check_height_on(
10331            platforms: &[TargetPlatform],
10332            decorator: impl Fn() -> BuildInputDecorator + Sync,
10333            height: f64,
10334        ) {
10335            for platform in platforms {
10336                test_widgets_variant(TargetPlatformVariant::only(*platform), |tester| {
10337                    tester.pump_widget(decorator().build());
10338                    assert_eq!(
10339                        get_container_rect(tester).height(),
10340                        height,
10341                        "on {platform:?}"
10342                    );
10343                });
10344            }
10345        }
10346
10347        fn compact_decoration_theme(app: &App) -> ThemeData {
10348            ThemeData::builder()
10349                .input_decoration_theme(
10350                    InputDecorationThemeData::new().visual_density(VisualDensity::COMPACT),
10351                )
10352                .build(app)
10353        }
10354
10355        fn compact_theme(app: &App) -> ThemeData {
10356            ThemeData::builder()
10357                .visual_density(VisualDensity::COMPACT)
10358                .build(app)
10359        }
10360
10361        fn standard_decoration_theme(app: &App) -> ThemeData {
10362            ThemeData::builder()
10363                .input_decoration_theme(
10364                    InputDecorationThemeData::new().visual_density(VisualDensity::STANDARD),
10365                )
10366                .build(app)
10367        }
10368
10369        fn standard_theme(app: &App) -> ThemeData {
10370            ThemeData::builder()
10371                .visual_density(VisualDensity::STANDARD)
10372                .build(app)
10373        }
10374
10375        /// `ThemeData(visualDensity: compact, inputDecorationTheme: (visualDensity: standard))`.
10376        fn compact_theme_with_standard_decoration_theme(app: &App) -> ThemeData {
10377            ThemeData::builder()
10378                .visual_density(VisualDensity::COMPACT)
10379                .input_decoration_theme(
10380                    InputDecorationThemeData::new().visual_density(VisualDensity::STANDARD),
10381                )
10382                .build(app)
10383        }
10384
10385        /// `ThemeData(visualDensity: compact, inputDecorationTheme: (visualDensity: comfortable))`.
10386        fn compact_theme_with_comfortable_decoration_theme(app: &App) -> ThemeData {
10387            ThemeData::builder()
10388                .visual_density(VisualDensity::COMPACT)
10389                .input_decoration_theme(
10390                    InputDecorationThemeData::new().visual_density(VisualDensity::COMFORTABLE),
10391                )
10392                .build(app)
10393        }
10394
10395        type ThemeFn = fn(&App) -> ThemeData;
10396
10397        /// The three density cases of a container kind: at the decoration, its theme, the theme.
10398        fn check_density_levels(
10399            decoration: fn() -> InputDecoration,
10400            density: VisualDensity,
10401            height: f64,
10402        ) {
10403            let (decoration_theme, theme): (ThemeFn, ThemeFn) = if density == VisualDensity::COMPACT
10404            {
10405                (compact_decoration_theme, compact_theme)
10406            } else {
10407                (standard_decoration_theme, standard_theme)
10408            };
10409            // Visual density configured at the decoration level.
10410            check_height_on(
10411                &ALL_PLATFORMS,
10412                || BuildInputDecorator::new(decoration().visual_density(density)),
10413                height,
10414            );
10415            // Visual density configured at the input decoration theme level.
10416            check_height_on(
10417                &ALL_PLATFORMS,
10418                || BuildInputDecorator::new(decoration()).theme(decoration_theme),
10419                height,
10420            );
10421            // Visual density configured at the theme level.
10422            check_height_on(
10423                &ALL_PLATFORMS,
10424                || BuildInputDecorator::new(decoration()).theme(theme),
10425                height,
10426            );
10427        }
10428
10429        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10430        // - default container height is 48dp on desktop'.
10431        #[test]
10432        fn a_filled_container_is_48_high_on_desktop() {
10433            check_height_on(
10434                &DESKTOP_PLATFORMS,
10435                || BuildInputDecorator::new(filled(false)),
10436                DESKTOP_CONTAINER_HEIGHT,
10437            );
10438        }
10439
10440        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10441        // - default container height is 48dp on all platforms when visual density is
10442        // VisualDensity.compact'.
10443        #[test]
10444        fn a_filled_container_is_48_high_on_every_platform_at_compact_density() {
10445            check_density_levels(|| filled(false), VisualDensity::COMPACT, 48.0);
10446        }
10447
10448        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10449        // - default container height is 56dp on all platforms when visual density if
10450        // VisualDensity.standard'.
10451        #[test]
10452        fn a_filled_container_is_56_high_on_every_platform_at_standard_density() {
10453            check_density_levels(|| filled(false), VisualDensity::STANDARD, 56.0);
10454        }
10455
10456        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10457        // - Visual density defined at the decoration level takes precedence'.
10458        #[test]
10459        fn a_filled_container_takes_the_decoration_density_over_the_themes() {
10460            test_widgets(|tester| {
10461                pump(
10462                    tester,
10463                    BuildInputDecorator::new(
10464                        filled(false).visual_density(VisualDensity::COMFORTABLE),
10465                    )
10466                    .theme(compact_theme_with_standard_decoration_theme),
10467                );
10468                assert_eq!(get_container_rect(tester).height(), 52.0);
10469            });
10470        }
10471
10472        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10473        // - Visual density defined at the input decoration theme level takes precedence'.
10474        #[test]
10475        fn a_filled_container_takes_the_decoration_theme_density_over_the_themes() {
10476            test_widgets(|tester| {
10477                pump(
10478                    tester,
10479                    BuildInputDecorator::new(filled(false))
10480                        .theme(compact_theme_with_comfortable_decoration_theme),
10481                );
10482                assert_eq!(get_container_rect(tester).height(), 52.0);
10483            });
10484        }
10485
10486        // input_decorator_test.dart 'Material3 - InputDecoration container - for filled text field
10487        // - Ambient activeIndicatorBorder is used'.
10488        #[test]
10489        fn a_filled_container_uses_the_ambient_active_indicator_border() {
10490            test_widgets(|tester| {
10491                let active_indicator_border = BorderSide {
10492                    color: Colors::AMBER.primary(),
10493                    width: 2.0,
10494                    ..BorderSide::default()
10495                };
10496                pump(
10497                    tester,
10498                    BuildInputDecorator::new(InputDecoration::new().label_text(LABEL_TEXT))
10499                        .input_decoration_theme(
10500                            InputDecorationThemeData::new()
10501                                .filled(true)
10502                                .active_indicator_border(active_indicator_border),
10503                        ),
10504                );
10505                assert_eq!(get_border_color(tester), active_indicator_border.color);
10506                assert_eq!(get_border_weight(tester), active_indicator_border.width);
10507            });
10508        }
10509
10510        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10511        // field - when field is enabled - container has correct height and shape'.
10512        #[test]
10513        fn an_outlined_enabled_container_has_the_m3_height_and_a_rounded_outline() {
10514            test_widgets(|tester| {
10515                check_outlined_shape(tester, BuildInputDecorator::new(outlined(false)));
10516            });
10517        }
10518
10519        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10520        // field - when field is enabled - container is painted correctly'.
10521        #[test]
10522        fn an_outlined_enabled_container_is_stroked_and_not_filled() {
10523            test_widgets(|tester| {
10524                check_outlined_painted(tester, BuildInputDecorator::new(outlined(false)));
10525            });
10526        }
10527
10528        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10529        // field - when field is enabled - outline has correct weight and color'.
10530        #[test]
10531        fn an_outlined_enabled_outline_is_outline_and_1_wide() {
10532            test_widgets(|tester| {
10533                check_border(
10534                    tester,
10535                    BuildInputDecorator::new(outlined(false)),
10536                    |theme| theme.color_scheme.outline(),
10537                    1.0,
10538                );
10539            });
10540        }
10541
10542        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10543        // field - when field is disabled - container has correct height and shape'.
10544        #[test]
10545        fn an_outlined_disabled_container_has_the_m3_height_and_a_rounded_outline() {
10546            test_widgets(|tester| {
10547                check_outlined_shape(
10548                    tester,
10549                    BuildInputDecorator::new(outlined(false).enabled(false)),
10550                );
10551            });
10552        }
10553
10554        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10555        // field - when field is disabled - container is painted correctly'.
10556        #[test]
10557        fn an_outlined_disabled_container_is_stroked_and_not_filled() {
10558            test_widgets(|tester| {
10559                check_outlined_painted(
10560                    tester,
10561                    BuildInputDecorator::new(outlined(false).enabled(false)),
10562                );
10563            });
10564        }
10565
10566        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10567        // field - when field is disabled - outline has correct weight and color'.
10568        #[test]
10569        fn an_outlined_disabled_outline_is_12_percent_on_surface_and_1_wide() {
10570            test_widgets(|tester| {
10571                check_border(
10572                    tester,
10573                    BuildInputDecorator::new(outlined(false).enabled(false)),
10574                    |theme| theme.color_scheme.on_surface().with_opacity(0.12),
10575                    1.0,
10576                );
10577            });
10578        }
10579
10580        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10581        // field - when field is hovered - container has correct height and shape'.
10582        #[test]
10583        fn an_outlined_hovered_container_has_the_m3_height_and_a_rounded_outline() {
10584            test_widgets(|tester| {
10585                check_outlined_shape(
10586                    tester,
10587                    BuildInputDecorator::new(outlined(false)).is_hovering(true),
10588                );
10589            });
10590        }
10591
10592        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10593        // field - when field is hovered - container is painted correctly'.
10594        #[test]
10595        fn an_outlined_hovered_container_is_stroked_and_not_filled() {
10596            test_widgets(|tester| {
10597                check_outlined_painted(
10598                    tester,
10599                    BuildInputDecorator::new(outlined(false)).is_hovering(true),
10600                );
10601            });
10602        }
10603
10604        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10605        // field - when field is hovered - outline has correct weight and color'.
10606        #[test]
10607        fn an_outlined_hovered_outline_is_on_surface_and_1_wide() {
10608            test_widgets(|tester| {
10609                check_border(
10610                    tester,
10611                    BuildInputDecorator::new(outlined(false)).is_hovering(true),
10612                    |theme| theme.color_scheme.on_surface(),
10613                    1.0,
10614                );
10615            });
10616        }
10617
10618        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10619        // field - when field is focused - container has correct height and shape'.
10620        #[test]
10621        fn an_outlined_focused_container_has_the_m3_height_and_a_rounded_outline() {
10622            test_widgets(|tester| {
10623                check_outlined_shape(
10624                    tester,
10625                    BuildInputDecorator::new(outlined(false)).is_focused(true),
10626                );
10627            });
10628        }
10629
10630        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10631        // field - when field is focused - container is painted correctly'.
10632        #[test]
10633        fn an_outlined_focused_container_is_stroked_and_not_filled() {
10634            test_widgets(|tester| {
10635                check_outlined_painted(
10636                    tester,
10637                    BuildInputDecorator::new(outlined(false)).is_focused(true),
10638                );
10639            });
10640        }
10641
10642        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10643        // field - when field is focused - outline has correct weight and color'.
10644        #[test]
10645        fn an_outlined_focused_outline_is_primary_and_2_wide() {
10646            test_widgets(|tester| {
10647                check_border(
10648                    tester,
10649                    BuildInputDecorator::new(outlined(false)).is_focused(true),
10650                    |theme| theme.color_scheme.primary(),
10651                    2.0,
10652                );
10653            });
10654        }
10655
10656        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10657        // field - when field is focused - outline has correct weight and color when focused and
10658        // hovered'.
10659        #[test]
10660        fn an_outlined_focused_and_hovered_outline_is_primary_and_2_wide() {
10661            test_widgets(|tester| {
10662                check_border(
10663                    tester,
10664                    BuildInputDecorator::new(outlined(false))
10665                        .is_focused(true)
10666                        .is_hovering(true),
10667                    |theme| theme.color_scheme.primary(),
10668                    2.0,
10669                );
10670            });
10671        }
10672
10673        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10674        // field - when field is in error - container has correct height and shape'.
10675        #[test]
10676        fn an_outlined_error_container_has_the_m3_height_and_a_rounded_outline() {
10677            test_widgets(|tester| {
10678                check_outlined_shape(tester, BuildInputDecorator::new(outlined(true)));
10679            });
10680        }
10681
10682        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10683        // field - when field is in error - container is painted correctly'.
10684        #[test]
10685        fn an_outlined_error_container_is_stroked_and_not_filled() {
10686            test_widgets(|tester| {
10687                check_outlined_painted(tester, BuildInputDecorator::new(outlined(true)));
10688            });
10689        }
10690
10691        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10692        // field - when field is in error - outline has correct weight and color'.
10693        #[test]
10694        fn an_outlined_error_outline_is_error_and_1_wide() {
10695            test_widgets(|tester| {
10696                check_border(
10697                    tester,
10698                    BuildInputDecorator::new(outlined(true)),
10699                    |theme| theme.color_scheme.error(),
10700                    1.0,
10701                );
10702            });
10703        }
10704
10705        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10706        // field - when field is in error - outline has correct weight and color when focused'.
10707        #[test]
10708        fn an_outlined_focused_error_outline_is_error_and_2_wide() {
10709            test_widgets(|tester| {
10710                check_border(
10711                    tester,
10712                    BuildInputDecorator::new(outlined(true)).is_focused(true),
10713                    |theme| theme.color_scheme.error(),
10714                    2.0,
10715                );
10716            });
10717        }
10718
10719        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10720        // field - when field is in error - outline has correct weight and color when hovered'.
10721        #[test]
10722        fn an_outlined_hovered_error_outline_is_on_error_container_and_1_wide() {
10723            test_widgets(|tester| {
10724                check_border(
10725                    tester,
10726                    BuildInputDecorator::new(outlined(true)).is_hovering(true),
10727                    |theme| theme.color_scheme.on_error_container(),
10728                    1.0,
10729                );
10730            });
10731        }
10732
10733        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10734        // field - when field is in error - outline has correct weight and color when focused and
10735        // hovered'.
10736        #[test]
10737        fn an_outlined_focused_and_hovered_error_outline_is_error_and_2_wide() {
10738            test_widgets(|tester| {
10739                check_border(
10740                    tester,
10741                    BuildInputDecorator::new(outlined(true))
10742                        .is_focused(true)
10743                        .is_hovering(true),
10744                    |theme| theme.color_scheme.error(),
10745                    2.0,
10746                );
10747            });
10748        }
10749
10750        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10751        // field - default container height is 48dp on desktop'.
10752        #[test]
10753        fn an_outlined_container_is_48_high_on_desktop() {
10754            check_height_on(
10755                &DESKTOP_PLATFORMS,
10756                || BuildInputDecorator::new(outlined(false)),
10757                DESKTOP_CONTAINER_HEIGHT,
10758            );
10759        }
10760
10761        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10762        // field - default container height is 48dp on all platforms when visual density is
10763        // VisualDensity.compact'.
10764        #[test]
10765        fn an_outlined_container_is_48_high_on_every_platform_at_compact_density() {
10766            check_density_levels(|| outlined(false), VisualDensity::COMPACT, 48.0);
10767        }
10768
10769        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10770        // field - default container height is 56dp on all platforms when visual density if
10771        // VisualDensity.standard'.
10772        #[test]
10773        fn an_outlined_container_is_56_high_on_every_platform_at_standard_density() {
10774            check_density_levels(|| outlined(false), VisualDensity::STANDARD, 56.0);
10775        }
10776
10777        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10778        // field - Visual density defined at the decoration level takes precedence'.
10779        #[test]
10780        fn an_outlined_container_takes_the_decoration_density_over_the_themes() {
10781            test_widgets(|tester| {
10782                pump(
10783                    tester,
10784                    BuildInputDecorator::new(
10785                        outlined(false).visual_density(VisualDensity::COMFORTABLE),
10786                    )
10787                    .theme(compact_theme_with_standard_decoration_theme),
10788                );
10789                assert_eq!(get_container_rect(tester).height(), 52.0);
10790            });
10791        }
10792
10793        // input_decorator_test.dart 'Material3 - InputDecoration container - for outlined text
10794        // field - Visual density defined at the input decoration theme level takes precedence'.
10795        #[test]
10796        fn an_outlined_container_takes_the_decoration_theme_density_over_the_themes() {
10797            test_widgets(|tester| {
10798                pump(
10799                    tester,
10800                    BuildInputDecorator::new(outlined(false))
10801                        .theme(compact_theme_with_comfortable_decoration_theme),
10802                );
10803                assert_eq!(get_container_rect(tester).height(), 52.0);
10804            });
10805        }
10806
10807        // input_decorator_test.dart 'Material3 - InputDecoration container - InputDecorator with
10808        // no input border'.
10809        #[test]
10810        fn a_decorator_with_no_input_border_has_a_zero_border_weight() {
10811            test_widgets(|tester| {
10812                pump(
10813                    tester,
10814                    BuildInputDecorator::new(InputDecoration::new().border(InputBorderRef::none()))
10815                        .is_empty(true),
10816                );
10817                assert_eq!(get_border_weight(tester), 0.0);
10818            });
10819        }
10820
10821        // input_decorator_test.dart 'Material3 - InputDecoration container - OutlineInputBorder
10822        // async lerp': the enabled border appears and disappears while the decorator animates
10823        // between them, without failing. Dart's tap awaits a completer between the two changes;
10824        // here each change is a pumped widget.
10825        #[test]
10826        fn an_enabled_border_that_comes_and_goes_mid_animation_lerps_without_failing() {
10827            test_widgets(|tester| {
10828                let decorator = |wait_is_over: bool| {
10829                    let mut decoration = InputDecoration::new().label_text("Test");
10830                    if wait_is_over {
10831                        decoration = decoration.enabled_border(
10832                            OutlineInputBorder::new().border_side(BorderSide {
10833                                color: Colors::BLUE.primary(),
10834                                ..BorderSide::default()
10835                            }),
10836                        );
10837                    }
10838                    MaterialApp::new()
10839                        .home(InputDecorator::new(decoration))
10840                        .into_widget()
10841                };
10842                tester.pump_widget(decorator(false));
10843                tester.pump_widget(decorator(true));
10844                tester.pump_by(K_TRANSITION_DURATION);
10845                tester.pump_widget(decorator(false));
10846                tester.pump_by(K_TRANSITION_DURATION);
10847                assert!(get_border(tester).is_some());
10848            });
10849        }
10850
10851        fn blue_side() -> BorderSide {
10852            BorderSide {
10853                color: Colors::BLUE.primary(),
10854                ..BorderSide::default()
10855            }
10856        }
10857
10858        fn red_side() -> BorderSide {
10859            BorderSide {
10860                color: Colors::RED.primary(),
10861                ..BorderSide::default()
10862            }
10863        }
10864
10865        // input_decorator_test.dart 'Material3 - InputDecoration container - InputBorder
10866        // equality'.
10867        #[test]
10868        fn input_borders_are_equal_when_their_sides_radii_and_gap_paddings_are() {
10869            // OutlineInputBorder's equality is defined by the borderRadius, borderSide, & gapPadding.
10870            let outline_input_border = OutlineInputBorder::new()
10871                .border_radius(BorderRadius::all(Radius::circular(9.0)))
10872                .border_side(blue_side())
10873                .gap_padding(32.0);
10874            assert!(
10875                outline_input_border.eq_shape(
10876                    &OutlineInputBorder::new()
10877                        .border_side(blue_side())
10878                        .border_radius(BorderRadius::all(Radius::circular(9.0)))
10879                        .gap_padding(32.0)
10880                )
10881            );
10882            assert!(!outline_input_border.eq_shape(&OutlineInputBorder::new()));
10883            assert!(
10884                !outline_input_border.eq_shape(
10885                    &OutlineInputBorder::new()
10886                        .border_side(red_side())
10887                        .border_radius(BorderRadius::all(Radius::circular(9.0)))
10888                        .gap_padding(32.0)
10889                )
10890            );
10891            assert!(
10892                !outline_input_border.eq_shape(
10893                    &OutlineInputBorder::new()
10894                        .border_side(blue_side())
10895                        .border_radius(BorderRadius::all(Radius::circular(10.0)))
10896                        .gap_padding(32.0)
10897                )
10898            );
10899            assert!(
10900                !outline_input_border.eq_shape(
10901                    &OutlineInputBorder::new()
10902                        .border_side(blue_side())
10903                        .border_radius(BorderRadius::all(Radius::circular(9.0)))
10904                        .gap_padding(33.0)
10905                )
10906            );
10907
10908            // UnderlineInputBorder's equality is defined by the borderSide and borderRadius.
10909            let top = |radius: f64| {
10910                BorderRadius::only(
10911                    Radius::circular(radius),
10912                    Radius::circular(radius),
10913                    Radius::ZERO,
10914                    Radius::ZERO,
10915                )
10916            };
10917            let underline_input_border = UnderlineInputBorder::new()
10918                .border_side(blue_side())
10919                .border_radius(top(5.0));
10920            assert!(
10921                underline_input_border.eq_shape(
10922                    &UnderlineInputBorder::new()
10923                        .border_side(blue_side())
10924                        .border_radius(top(5.0))
10925                )
10926            );
10927            assert!(!underline_input_border.eq_shape(&UnderlineInputBorder::new()));
10928            assert!(
10929                !underline_input_border.eq_shape(
10930                    &UnderlineInputBorder::new()
10931                        .border_side(red_side())
10932                        .border_radius(top(5.0))
10933                )
10934            );
10935            assert!(
10936                !underline_input_border.eq_shape(
10937                    &UnderlineInputBorder::new()
10938                        .border_side(blue_side())
10939                        .border_radius(top(6.0))
10940                )
10941            );
10942        }
10943
10944        // input_decorator_test.dart 'Material3 - InputDecoration container - OutlineInputBorder
10945        // borders scale down to fit when large values are passed in'.
10946        #[test]
10947        fn an_outline_with_radii_larger_than_the_decorator_fills_its_rrect() {
10948            test_widgets(|tester| {
10949                const LARGER_BORDER_RADIUS: f64 = 200.0;
10950                const SMALLER_BORDER_RADIUS: f64 = 100.0;
10951                const INPUT_DECORATOR_HEIGHT: f64 = 56.0;
10952                const INPUT_DECORATOR_WIDTH: f64 = 800.0;
10953                let border_radius = BorderRadius::only(
10954                    // Intentionally large values that are larger than the InputDecorator.
10955                    Radius::circular(SMALLER_BORDER_RADIUS),
10956                    Radius::circular(LARGER_BORDER_RADIUS),
10957                    Radius::circular(LARGER_BORDER_RADIUS),
10958                    Radius::circular(SMALLER_BORDER_RADIUS),
10959                );
10960                pump(
10961                    tester,
10962                    BuildInputDecorator::new(
10963                        InputDecoration::new()
10964                            .filled(true)
10965                            .fill_color(Color::new(0xFF00FF00))
10966                            .label_text("label text")
10967                            .border(OutlineInputBorder::new().border_radius(border_radius)),
10968                    ),
10969                );
10970                assert_paints(
10971                    &border_painter_ops(tester),
10972                    &[
10973                        PaintCall::Save,
10974                        PaintCall::RRect {
10975                            rrect: Some(border_radius.to_rrect(Rect::from_ltwh(
10976                                0.0,
10977                                0.0,
10978                                INPUT_DECORATOR_WIDTH,
10979                                INPUT_DECORATOR_HEIGHT,
10980                            ))),
10981                            color: Some(Color::new(0xFF00FF00)),
10982                            style: Some(PaintedStyle::Fill),
10983                            has_mask_filter: None,
10984                        },
10985                        PaintCall::Restore,
10986                    ],
10987                );
10988            });
10989        }
10990
10991        // input_decorator_test.dart 'Material3 - InputDecoration container - rounded
10992        // OutlineInputBorder with zero padding just wraps the label'.
10993        #[test]
10994        fn a_rounded_outline_with_zero_gap_padding_fills_its_rrect() {
10995            test_widgets(|tester| {
10996                const BORDER_RADIUS: f64 = 30.0;
10997                const LABEL: &str = "label text";
10998                const INPUT_DECORATOR_HEIGHT: f64 = 56.0;
10999                const INPUT_DECORATOR_WIDTH: f64 = 800.0;
11000                pump(
11001                    tester,
11002                    BuildInputDecorator::new(
11003                        InputDecoration::new()
11004                            .filled(true)
11005                            .fill_color(Color::new(0xFF00FF00))
11006                            .label_text(LABEL)
11007                            .border(
11008                                OutlineInputBorder::new()
11009                                    .border_radius(BorderRadius::all(Radius::circular(
11010                                        BORDER_RADIUS,
11011                                    )))
11012                                    .gap_padding(0.0),
11013                            ),
11014                    ),
11015                );
11016                expect(tester, &find::text(LABEL), finds_one_widget());
11017                assert_paints(
11018                    &border_painter_ops(tester),
11019                    &[
11020                        PaintCall::Save,
11021                        PaintCall::RRect {
11022                            rrect: Some(
11023                                BorderRadius::all(Radius::circular(BORDER_RADIUS)).to_rrect(
11024                                    Rect::from_ltwh(
11025                                        0.0,
11026                                        0.0,
11027                                        INPUT_DECORATOR_WIDTH,
11028                                        INPUT_DECORATOR_HEIGHT,
11029                                    ),
11030                                ),
11031                            ),
11032                            color: Some(Color::new(0xFF00FF00)),
11033                            style: Some(PaintedStyle::Fill),
11034                            has_mask_filter: None,
11035                        },
11036                        PaintCall::Restore,
11037                    ],
11038                );
11039            });
11040        }
11041
11042        // input_decorator_test.dart 'Material3 - InputDecoration container - OutlineInputBorder
11043        // with BorderRadius.zero should draw a rectangular border'.
11044        #[test]
11045        fn an_outline_with_a_zero_radius_draws_a_rectangle() {
11046            test_widgets(|tester| {
11047                const LABEL: &str = "Flutter";
11048                const INPUT_DECORATOR_HEIGHT: f64 = 56.0;
11049                const INPUT_DECORATOR_WIDTH: f64 = 800.0;
11050                const BORDER_WIDTH: f64 = 4.0;
11051                pump(
11052                    tester,
11053                    BuildInputDecorator::new(
11054                        InputDecoration::new()
11055                            .filled(false)
11056                            .label_text(LABEL)
11057                            .focused_border(
11058                                OutlineInputBorder::new()
11059                                    .border_radius(BorderRadius::ZERO)
11060                                    .border_side(BorderSide {
11061                                        width: BORDER_WIDTH,
11062                                        color: Colors::RED.primary(),
11063                                        ..BorderSide::default()
11064                                    }),
11065                            ),
11066                    )
11067                    .is_focused(true),
11068                );
11069                expect(tester, &find::text(LABEL), finds_one_widget());
11070                assert_paints(
11071                    &border_painter_ops(tester),
11072                    &[
11073                        PaintCall::Save,
11074                        PaintCall::Path {
11075                            color: None,
11076                            style: None,
11077                            includes: vec![
11078                                // Corner points in the middle of the border line should be in the path.
11079                                // The path is not filled and borderWidth is 4.0 so Offset(2.0, 2.0) is in the path and Offset(1.0, 1.0) is not.
11080                                // See Skia SkPath::contains method.
11081
11082                                // Top-left.
11083                                Offset::new(BORDER_WIDTH / 2.0, BORDER_WIDTH / 2.0),
11084                                // Top-right.
11085                                Offset::new(
11086                                    INPUT_DECORATOR_WIDTH - 1.0 - BORDER_WIDTH / 2.0,
11087                                    BORDER_WIDTH / 2.0,
11088                                ),
11089                                // Bottom-left.
11090                                Offset::new(
11091                                    BORDER_WIDTH / 2.0,
11092                                    INPUT_DECORATOR_HEIGHT - 1.0 - BORDER_WIDTH / 2.0,
11093                                ),
11094                                // Bottom-right.
11095                                Offset::new(
11096                                    INPUT_DECORATOR_WIDTH - 1.0 - BORDER_WIDTH / 2.0,
11097                                    INPUT_DECORATOR_HEIGHT - 1.0 - BORDER_WIDTH / 2.0,
11098                                ),
11099                            ],
11100                            excludes: vec![
11101                                // The path is not filled and borderWidth is 4.0 so the path should not contains the corner points.
11102                                // See Skia SkPath::contains method.
11103
11104                                // Top-left.
11105                                Offset::ZERO,
11106                                // Top-right.
11107                                Offset::new(INPUT_DECORATOR_WIDTH - 1.0, 0.0),
11108                                // Bottom-left.
11109                                Offset::new(0.0, INPUT_DECORATOR_HEIGHT - 1.0),
11110                                // Bottom-right.
11111                                Offset::new(
11112                                    INPUT_DECORATOR_WIDTH - 1.0,
11113                                    INPUT_DECORATOR_HEIGHT - 1.0,
11114                                ),
11115                            ],
11116                        },
11117                        PaintCall::Restore,
11118                    ],
11119                );
11120            });
11121        }
11122
11123        // input_decorator_test.dart 'Material3 - InputDecoration container - InputDecorator
11124        // OutlineInputBorder fillColor is clipped by border'.
11125        #[test]
11126        fn an_outline_fill_is_its_rounded_rect_under_the_stroked_outline() {
11127            test_widgets(|tester| {
11128                pump(
11129                    tester,
11130                    BuildInputDecorator::new(
11131                        InputDecoration::new()
11132                            .filled(true)
11133                            .fill_color(Color::new(0xFF00FF00))
11134                            .border(
11135                                OutlineInputBorder::new()
11136                                    .border_radius(BorderRadius::all(Radius::circular(12.0))),
11137                            ),
11138                    ),
11139                );
11140                assert_paints(
11141                    &decorator_ops(tester),
11142                    &[
11143                        // The border's outer path, a rounded rectangle.
11144                        PaintCall::RRect {
11145                            rrect: Some(
11146                                BorderRadius::all(Radius::circular(12.0))
11147                                    .to_rrect(Rect::from_ltwh(0.0, 0.0, 800.0, 56.0)),
11148                            ),
11149                            color: Some(Color::new(0xFF00FF00)),
11150                            style: Some(PaintedStyle::Fill),
11151                            has_mask_filter: None,
11152                        },
11153                        // Border outline. The rrect is the -center- of the 1.0 stroked outline.
11154                        PaintCall::RRect {
11155                            rrect: Some(RRect::from_ltrbr(
11156                                0.5,
11157                                0.5,
11158                                799.5,
11159                                55.5,
11160                                Radius::circular(11.5),
11161                            )),
11162                            color: None,
11163                            style: Some(PaintedStyle::Stroke(Some(1.0))),
11164                            has_mask_filter: None,
11165                        },
11166                    ],
11167                );
11168            });
11169        }
11170
11171        const STROKE_BORDER_WIDTH: f64 = 4.0;
11172        const STROKE_BORDER_RADIUS: f64 = 12.0;
11173        const STROKE_DECORATOR_WIDTH: f64 = 800.0;
11174        const STROKE_DECORATOR_HEIGHT: f64 = 56.0;
11175
11176        /// Dart's `testStrokeAlign` of the 'OutlineInputBorder strokeAlign' group.
11177        fn check_stroke_align(tester: &mut WidgetTester, stroke_align: f64, expected_rrect: RRect) {
11178            pump(
11179                tester,
11180                BuildInputDecorator::new(
11181                    InputDecoration::new()
11182                        .filled(true)
11183                        .fill_color(Color::new(0xFF00FF00))
11184                        .enabled_border(
11185                            OutlineInputBorder::new()
11186                                .border_radius(BorderRadius::all(Radius::circular(
11187                                    STROKE_BORDER_RADIUS,
11188                                )))
11189                                .border_side(BorderSide {
11190                                    width: STROKE_BORDER_WIDTH,
11191                                    stroke_align,
11192                                    ..BorderSide::default()
11193                                }),
11194                        ),
11195                ),
11196            );
11197            assert_paints(
11198                &decorator_ops(tester),
11199                &[
11200                    // Background fill of the InputDecorator.
11201                    PaintCall::RRect {
11202                        rrect: Some(RRect::from_ltrbr(
11203                            0.0,
11204                            0.0,
11205                            STROKE_DECORATOR_WIDTH,
11206                            STROKE_DECORATOR_HEIGHT,
11207                            Radius::circular(STROKE_BORDER_RADIUS),
11208                        )),
11209                        color: Some(Color::new(0xFF00FF00)),
11210                        style: Some(PaintedStyle::Fill),
11211                        has_mask_filter: None,
11212                    },
11213                    // The stroked OutlineInputBorder.
11214                    PaintCall::RRect {
11215                        rrect: Some(expected_rrect),
11216                        color: None,
11217                        style: Some(PaintedStyle::Stroke(Some(STROKE_BORDER_WIDTH))),
11218                        has_mask_filter: None,
11219                    },
11220                ],
11221            );
11222        }
11223
11224        // input_decorator_test.dart 'Material3 - InputDecoration container - OutlineInputBorder
11225        // strokeAlign - strokeAlignOutside should draw border outside bounds'.
11226        #[test]
11227        fn an_outline_aligned_outside_strokes_outside_the_decorator() {
11228            test_widgets(|tester| {
11229                check_stroke_align(
11230                    tester,
11231                    BorderSide::STROKE_ALIGN_OUTSIDE,
11232                    RRect::from_ltrbr(
11233                        -STROKE_BORDER_WIDTH / 2.0,
11234                        -STROKE_BORDER_WIDTH / 2.0,
11235                        STROKE_DECORATOR_WIDTH + STROKE_BORDER_WIDTH / 2.0,
11236                        STROKE_DECORATOR_HEIGHT + STROKE_BORDER_WIDTH / 2.0,
11237                        Radius::circular(STROKE_BORDER_RADIUS + STROKE_BORDER_WIDTH / 2.0),
11238                    ),
11239                );
11240            });
11241        }
11242
11243        // input_decorator_test.dart 'Material3 - InputDecoration container - OutlineInputBorder
11244        // strokeAlign - strokeAlignCenter should draw border between bounds'.
11245        #[test]
11246        fn an_outline_aligned_center_strokes_on_the_decorator_edge() {
11247            test_widgets(|tester| {
11248                check_stroke_align(
11249                    tester,
11250                    BorderSide::STROKE_ALIGN_CENTER,
11251                    RRect::from_ltrbr(
11252                        0.0,
11253                        0.0,
11254                        STROKE_DECORATOR_WIDTH,
11255                        STROKE_DECORATOR_HEIGHT,
11256                        Radius::circular(STROKE_BORDER_RADIUS),
11257                    ),
11258                );
11259            });
11260        }
11261
11262        // input_decorator_test.dart 'Material3 - InputDecoration container - OutlineInputBorder
11263        // strokeAlign - strokeAlignInside should draw border inside bounds'.
11264        #[test]
11265        fn an_outline_aligned_inside_strokes_inside_the_decorator() {
11266            test_widgets(|tester| {
11267                check_stroke_align(
11268                    tester,
11269                    BorderSide::STROKE_ALIGN_INSIDE,
11270                    RRect::from_ltrbr(
11271                        STROKE_BORDER_WIDTH / 2.0,
11272                        STROKE_BORDER_WIDTH / 2.0,
11273                        STROKE_DECORATOR_WIDTH - STROKE_BORDER_WIDTH / 2.0,
11274                        STROKE_DECORATOR_HEIGHT - STROKE_BORDER_WIDTH / 2.0,
11275                        Radius::circular(STROKE_BORDER_RADIUS - STROKE_BORDER_WIDTH / 2.0),
11276                    ),
11277                );
11278            });
11279        }
11280
11281        // input_decorator_test.dart 'Material3 - InputDecoration container - InputDecorator
11282        // UnderlineInputBorder fillColor is clipped by border'.
11283        #[test]
11284        fn an_underline_with_rounded_bottom_corners_paints_its_bottom_as_a_ring() {
11285            test_widgets(|tester| {
11286                pump(
11287                    tester,
11288                    BuildInputDecorator::new(
11289                        InputDecoration::new()
11290                            .filled(true)
11291                            .fill_color(Color::new(0xFF00FF00))
11292                            .border(
11293                                UnderlineInputBorder::new().border_radius(BorderRadius::only(
11294                                    Radius::ZERO,
11295                                    Radius::ZERO,
11296                                    Radius::circular(12.0),
11297                                    Radius::circular(12.0),
11298                                )),
11299                            ),
11300                    ),
11301                );
11302                // Fill is the border's outer path, a rounded rectangle.
11303                assert_paints(
11304                    &decorator_ops(tester),
11305                    &[PaintCall::DRRect {
11306                        outer: Some(RRect::from_ltrb_and_corners(
11307                            0.0,
11308                            0.0,
11309                            800.0,
11310                            48.0,
11311                            Radius::ZERO,
11312                            Radius::ZERO,
11313                            Radius::elliptical(12.0, 12.0),
11314                            Radius::elliptical(12.0, 12.0),
11315                        )),
11316                        inner: Some(RRect::from_ltrb_and_corners(
11317                            0.0,
11318                            0.0,
11319                            800.0,
11320                            47.0,
11321                            Radius::ZERO,
11322                            Radius::ZERO,
11323                            Radius::elliptical(12.0, 11.0),
11324                            Radius::elliptical(12.0, 11.0),
11325                        )),
11326                        color: None,
11327                        style: Some(PaintedStyle::Fill),
11328                    }],
11329                );
11330            });
11331        }
11332
11333        /// Dart's `(Canvas canvas) => border.paint(canvas, canvasRect)` as a `paints` subject.
11334        fn ops_of_border(border: &dyn ShapeBorder, rect: Rect) -> Vec<Op> {
11335            let mut canvas = Canvas::new();
11336            border.paint(&mut canvas, rect, None);
11337            canvas.build().ops().to_vec()
11338        }
11339
11340        // input_decorator_test.dart 'Material3 - InputDecoration container - UnderlineInputBorder
11341        // clips top border to prevent anti-aliasing glitches'.
11342        #[test]
11343        fn an_underline_paints_only_its_bottom_side_with_bottom_radii_clamped_to_half_its_height() {
11344            let canvas_rect = Rect::from_ltwh(0.0, 0.0, 100.0, 100.0);
11345            let border = UnderlineInputBorder::new()
11346                .border_radius(BorderRadius::all(Radius::circular(12.0)));
11347            assert_paints(
11348                &ops_of_border(&border, canvas_rect),
11349                &[PaintCall::DRRect {
11350                    outer: Some(RRect::from_ltrb_and_corners(
11351                        0.0,
11352                        0.0,
11353                        100.0,
11354                        100.0,
11355                        Radius::ZERO,
11356                        Radius::ZERO,
11357                        Radius::elliptical(12.0, 12.0),
11358                        Radius::elliptical(12.0, 12.0),
11359                    )),
11360                    inner: Some(RRect::from_ltrb_and_corners(
11361                        0.0,
11362                        0.0,
11363                        100.0,
11364                        99.0,
11365                        Radius::ZERO,
11366                        Radius::ZERO,
11367                        Radius::elliptical(12.0, 11.0),
11368                        Radius::elliptical(12.0, 11.0),
11369                    )),
11370                    color: None,
11371                    style: None,
11372                }],
11373            );
11374
11375            let border2 = UnderlineInputBorder::new()
11376                .border_radius(BorderRadius::all(Radius::circular(60.0)));
11377            assert!(
11378                paints(
11379                    &ops_of_border(&border2, canvas_rect),
11380                    &[PaintCall::DRRect {
11381                        outer: Some(RRect::from_ltrb_and_corners(
11382                            0.0,
11383                            0.0,
11384                            100.0,
11385                            100.0,
11386                            Radius::ZERO,
11387                            Radius::ZERO,
11388                            Radius::elliptical(50.0, 50.0),
11389                            Radius::elliptical(50.0, 50.0),
11390                        )),
11391                        inner: Some(RRect::from_ltrb_and_corners(
11392                            0.0,
11393                            0.0,
11394                            100.0,
11395                            99.0,
11396                            Radius::ZERO,
11397                            Radius::ZERO,
11398                            Radius::elliptical(50.0, 49.0),
11399                            Radius::elliptical(50.0, 49.0),
11400                        )),
11401                        color: None,
11402                        style: None
11403                    }]
11404                )
11405                .is_ok(),
11406                "clamp is expected"
11407            );
11408        }
11409
11410        // input_decorator_test.dart 'Material3 - InputDecoration container - UnderlineInputBorder
11411        // draws bottom border inside container bounds'.
11412        #[test]
11413        fn an_underline_draws_its_line_inside_the_bottom_of_the_rect() {
11414            let canvas_rect = Rect::from_ltwh(0.0, 0.0, 100.0, 100.0);
11415            const BORDER_WIDTH: f64 = 2.0;
11416            let border = UnderlineInputBorder::new().border_side(BorderSide {
11417                width: BORDER_WIDTH,
11418                ..BorderSide::default()
11419            });
11420            assert_paints(
11421                &ops_of_border(&border, canvas_rect),
11422                &[PaintCall::line(
11423                    Offset::new(0.0, canvas_rect.height() - BORDER_WIDTH / 2.0),
11424                    Offset::new(100.0, canvas_rect.height() - BORDER_WIDTH / 2.0),
11425                    Some(BORDER_WIDTH),
11426                )],
11427            );
11428        }
11429
11430        /// The `buildFrame` of the label-gap cases: a `RepaintBoundary` around `decorator` in a
11431        /// padded, centred `Container` of a `Scaffold`'s body.
11432        fn gap_frame(text_direction: TextDirection, decorator: InputDecorator) -> WidgetRef {
11433            MaterialApp::new()
11434                .home(
11435                    Scaffold::new().body(
11436                        Container::new()
11437                            .padding(EdgeInsetsGeometry::all(16.0))
11438                            .alignment(AlignmentGeometry::Alignment(Alignment::CENTER))
11439                            .child(waft_widgets::Directionality::new(
11440                                text_direction,
11441                                RepaintBoundary::new().child(decorator),
11442                            )),
11443                    ),
11444                )
11445                .into_widget()
11446        }
11447
11448        /// `point` in the border container's coordinates: Dart's `borderBox.globalToLocal(point)`.
11449        fn border_local(tester: &WidgetTester, point: Offset) -> Offset {
11450            let element = find_border_painter(tester).expect("a border painter");
11451            let app = tester.cell.borrow();
11452            let border_box =
11453                InputDecorator::container_of(&app, element).expect("a decorator container");
11454            border_box.global_to_local(&app, point, None)
11455        }
11456
11457        // input_decorator_test.dart 'Material3 - InputDecoration container - OutlineBorder starts
11458        // at the right position when border radius is taller than horizontal content padding'.
11459        #[test]
11460        fn an_outline_with_a_tall_radius_starts_its_gap_at_the_label() {
11461            test_widgets(|tester| {
11462                let decorator = || {
11463                    InputDecorator::new(
11464                        InputDecoration::new().label_text(LABEL_TEXT).border(
11465                            OutlineInputBorder::new()
11466                                .border_radius(BorderRadius::all(Radius::circular(30.0)))
11467                                .gap_padding(0.0),
11468                        ),
11469                    )
11470                    .is_focused(true)
11471                    .is_empty(true)
11472                };
11473                tester.pump_widget(gap_frame(TextDirection::Ltr, decorator()));
11474                // Convert label bottom left offset to border path coordinate system.
11475                let label_bottom_left_local_to_border =
11476                    border_local(tester, get_label_rect(tester).bottom_left());
11477                assert_paints(
11478                    &border_painter_ops(tester),
11479                    &[
11480                        PaintCall::Save,
11481                        PaintCall::Path { color: None, style: None, includes: // The points just before the label bottom left corner should be part of the border.
11482                            vec![
11483                                label_bottom_left_local_to_border + Offset::new(-1.0, 0.0),
11484                                label_bottom_left_local_to_border + Offset::new(-1.0, -1.0),
11485                            ], excludes: // The label bottom left corner should not be part of the border.
11486                            vec![label_bottom_left_local_to_border] },
11487                        PaintCall::Restore,
11488                    ],
11489                );
11490
11491                tester.pump_widget(gap_frame(TextDirection::Rtl, decorator()));
11492                // Convert label bottom right offset to border path coordinate system.
11493                let label_bottom_right_local_to_border =
11494                    border_local(tester, get_label_rect(tester).bottom_right());
11495                assert_paints(
11496                    &border_painter_ops(tester),
11497                    &[
11498                        PaintCall::Save,
11499                        PaintCall::Path { color: None, style: None, includes: // The points just after the label bottom right corner should be part of the border.
11500                            vec![
11501                                label_bottom_right_local_to_border + Offset::new(1.0, 0.0),
11502                                label_bottom_right_local_to_border + Offset::new(1.0, -1.0),
11503                            ], excludes: // The label bottom right corner should not be part of the border.
11504                            vec![label_bottom_right_local_to_border] },
11505                        PaintCall::Restore,
11506                    ],
11507                );
11508            });
11509        }
11510
11511        // input_decorator_test.dart 'Material3 - InputDecoration container - OutlineBorder does
11512        // not overlap with the label at the default radius'.
11513        #[test]
11514        fn an_outline_at_the_default_radius_leaves_a_gap_exactly_under_the_label() {
11515            test_widgets(|tester| {
11516                let decorator = || {
11517                    InputDecorator::new(
11518                        InputDecoration::new()
11519                            .label_text(LABEL_TEXT)
11520                            .border(OutlineInputBorder::new().gap_padding(0.0)),
11521                    )
11522                    .is_focused(true)
11523                };
11524                for text_direction in [TextDirection::Ltr, TextDirection::Rtl] {
11525                    tester.pump_widget(gap_frame(text_direction, decorator()));
11526                    let label_rect = get_label_rect(tester);
11527                    let center_left = border_local(tester, label_rect.center_left());
11528                    let center_right = border_local(tester, label_rect.center_right());
11529                    assert!(
11530                        paints(
11531                            &border_painter_ops(tester),
11532                            &[
11533                                PaintCall::Save,
11534                                PaintCall::Path { color: None, style: None, includes: // The points of the label edge should be part of the border.
11535                                    vec![center_left, center_right], excludes: // The points inside the label should not be part of the border.
11536                                    vec![
11537                                        center_left + Offset::new(1.0, 0.0),
11538                                        center_right + Offset::new(-1.0, 0.0),
11539                                    ] },
11540                                PaintCall::Restore,
11541                            ]
11542                        )
11543                        .is_ok(),
11544                        "{text_direction:?}"
11545                    );
11546                }
11547            });
11548        }
11549
11550        // input_decorator_test.dart 'Material3 - InputDecoration container - OutlineBorder does
11551        // not draw over label when input decorator is focused and has an icon'.
11552        #[test]
11553        fn an_outline_with_an_icon_leaves_its_gap_under_the_label() {
11554            test_widgets(|tester| {
11555                let decorator = || {
11556                    InputDecorator::new(
11557                        InputDecoration::new()
11558                            .icon(Icon::new(Some(Icons::insert_link())))
11559                            .label_text(LABEL_TEXT)
11560                            .border(OutlineInputBorder::new()),
11561                    )
11562                    .is_focused(true)
11563                    .is_empty(true)
11564                };
11565                for text_direction in [TextDirection::Ltr, TextDirection::Rtl] {
11566                    tester.pump_widget(gap_frame(text_direction, decorator()));
11567                    let label_rect = get_label_rect(tester);
11568                    let center_left = border_local(tester, label_rect.center_left());
11569                    let center_right = border_local(tester, label_rect.center_right());
11570                    assert!(
11571                        paints(
11572                            &border_painter_ops(tester),
11573                            &[
11574                                PaintCall::Save,
11575                                PaintCall::Path {
11576                                    color: None,
11577                                    style: None,
11578                                    includes: Vec::new(),
11579                                    excludes: vec![center_left, center_right]
11580                                },
11581                                PaintCall::Restore,
11582                            ]
11583                        )
11584                        .is_ok(),
11585                        "{text_direction:?}"
11586                    );
11587                }
11588            });
11589        }
11590    }
11591
11592    // input_decorator_test.dart's label and hint cases.
11593    mod label_and_hint {
11594        #![allow(deprecated)]
11595        use waft_widgets::testing::{WidgetTester, test_widgets};
11596
11597        use std::time::Duration;
11598
11599        use waft_embedder::{Color, Offset, Rect, Size};
11600        use waft_painting::{AnyColor, BorderSide, TextDirection, TextOverflow, TextStyle};
11601        use waft_widgets::{
11602            AnyElement, Center, FadeTransition, Icon, IntoWidget, RichText, SizedBox, Text,
11603            WidgetRef, downcast_widget,
11604        };
11605
11606        use super::super::*;
11607        use super::common::K_TRANSITION_DURATION;
11608        use super::common::*;
11609        use crate::colors::Colors;
11610        use crate::icons::Icons;
11611        use crate::input_border::OutlineInputBorder;
11612        use crate::theme::Theme;
11613        use crate::theme_data::{ThemeData, VisualDensity};
11614
11615        fn ms(milliseconds: u64) -> Duration {
11616            Duration::from_millis(milliseconds)
11617        }
11618
11619        /// Dart's `Theme.of(tester.element(findDecorator()))`.
11620        fn decorator_theme(tester: &WidgetTester) -> Rc<ThemeData> {
11621            let element = tester.element(find::by_type::<InputDecorator>());
11622            let mut app = tester.cell.borrow_mut();
11623            Theme::of(&mut app, element)
11624        }
11625
11626        fn color_of(style: &TextStyle) -> Option<Color> {
11627            style.color.as_ref().map(AnyColor::color)
11628        }
11629
11630        /// Dart's `getInputRect(tester)`.
11631        fn get_input_rect(tester: &WidgetTester) -> Rect {
11632            tester.get_rect(find::text(INPUT_TEXT))
11633        }
11634
11635        /// Dart's `getHintRect(tester)`.
11636        fn get_hint_rect(tester: &WidgetTester) -> Rect {
11637            tester.get_rect(find::text(HINT_TEXT))
11638        }
11639
11640        /// The hint's `Text`.
11641        fn find_hint(tester: &WidgetTester) -> AnyElement {
11642            tester.element(find::text(HINT_TEXT))
11643        }
11644
11645        /// Dart's `getHintOpacity(tester)`: the opacity of the nearest `FadeTransition` above the
11646        /// hint.
11647        fn get_hint_opacity(tester: &WidgetTester) -> f64 {
11648            let hint = find_hint(tester);
11649            let fade = tester
11650                .ancestors(hint)
11651                .into_iter()
11652                .find(|element| {
11653                    let app = tester.cell.borrow();
11654                    downcast_widget::<FadeTransition>(&**element.widget(&app)).is_some()
11655                })
11656                .expect("a FadeTransition above the hint");
11657            let opacity = tester.widget(fade, |fade: &FadeTransition| fade.opacity.clone());
11658            let app = tester.cell.borrow();
11659            opacity.value(&app)
11660        }
11661
11662        /// Dart's `getHintStyle(tester)`: the style of the `RichText` the hint's `Text` builds.
11663        fn get_hint_style(tester: &WidgetTester) -> TextStyle {
11664            let rich_text = tester.element(find::descendant(
11665                find::text(HINT_TEXT),
11666                find::by_type::<RichText>(),
11667            ));
11668            tester.widget(rich_text, |rich_text: &RichText| {
11669                rich_text.text.style().cloned().expect("a style")
11670            })
11671        }
11672
11673        fn pump(tester: &mut WidgetTester, decorator: BuildInputDecorator) {
11674            tester.pump_widget(decorator.build());
11675        }
11676
11677        // ----- Material3 - InputDecoration label -----
11678
11679        /// The label style expected of a decorator showing its label at rest: `bodyLarge` in
11680        /// `color` with its line height forced to 1.0.
11681        fn expected_label_style(theme: &ThemeData, color: Color) -> TextStyle {
11682            theme
11683                .text_theme
11684                .body_large
11685                .clone()
11686                .expect("bodyLarge")
11687                .copy_with()
11688                .color(color)
11689                .height(1.0)
11690        }
11691
11692        fn filled_label() -> InputDecoration {
11693            InputDecoration::new().filled(true).label_text(LABEL_TEXT)
11694        }
11695
11696        fn outlined_label() -> InputDecoration {
11697            InputDecoration::new()
11698                .border(OutlineInputBorder::new())
11699                .label_text(LABEL_TEXT)
11700                .helper_text(HELPER_TEXT)
11701        }
11702
11703        fn check_label_color(
11704            tester: &mut WidgetTester,
11705            decorator: BuildInputDecorator,
11706            expected: fn(&ThemeData) -> Color,
11707        ) {
11708            pump(tester, decorator);
11709            let theme = decorator_theme(tester);
11710            assert_eq!(color_of(&get_label_style(tester)), Some(expected(&theme)));
11711        }
11712
11713        // input_decorator_test.dart 'Material3 - InputDecoration label - for filled text field -
11714        // label and input horizontal positions are M3 compliant in LTR'.
11715        #[test]
11716        fn filled_label_and_input_start_at_the_padding_and_the_input_gap_in_ltr() {
11717            test_widgets(|tester| {
11718                pump(
11719                    tester,
11720                    BuildInputDecorator::new(
11721                        InputDecoration::new().filled(true).label_text(LABEL_TEXT),
11722                    ),
11723                );
11724                assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, 56.0));
11725                let label_and_input_start = 12.0 + 4.0; // Content left padding + default input gap.
11726                assert_eq!(get_label_rect(tester).left, label_and_input_start);
11727                assert_eq!(get_input_rect(tester).left, label_and_input_start);
11728            });
11729        }
11730
11731        // input_decorator_test.dart 'Material3 - InputDecoration label - for filled text field -
11732        // label and input horizontal positions are M3 compliant in RTL'.
11733        #[test]
11734        fn filled_label_and_input_start_at_the_padding_and_the_input_gap_in_rtl() {
11735            test_widgets(|tester| {
11736                pump(
11737                    tester,
11738                    BuildInputDecorator::new(
11739                        InputDecoration::new().filled(true).label_text(LABEL_TEXT),
11740                    )
11741                    .text_direction(TextDirection::Rtl),
11742                );
11743                assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, 56.0));
11744                let label_and_input_start = 12.0 + 4.0; // Content left padding + default input gap.
11745                assert_eq!(get_label_rect(tester).right, 800.0 - label_and_input_start);
11746                assert_eq!(get_input_rect(tester).right, 800.0 - label_and_input_start);
11747            });
11748        }
11749
11750        // input_decorator_test.dart 'Material3 - InputDecoration label - for filled text field -
11751        // when field is enabled - label text has correct style'.
11752        #[test]
11753        fn filled_enabled_label_text_has_body_large_in_on_surface_variant() {
11754            test_widgets(|tester| {
11755                pump(tester, BuildInputDecorator::new(filled_label()));
11756                let theme = decorator_theme(tester);
11757                // Current input decorator implementation forces line height to 1.0,
11758                // this is not compliant with M3 spec.
11759                let expected =
11760                    expected_label_style(&theme, theme.color_scheme.on_surface_variant());
11761                assert_eq!(get_label_style(tester), expected);
11762            });
11763        }
11764
11765        // input_decorator_test.dart 'Material3 - InputDecoration label - for filled text field -
11766        // when field is disabled - label text has correct color'.
11767        #[test]
11768        fn filled_disabled_label_text_is_on_surface_at_38_percent() {
11769            test_widgets(|tester| {
11770                check_label_color(
11771                    tester,
11772                    BuildInputDecorator::new(filled_label().enabled(false)),
11773                    |theme| theme.color_scheme.on_surface().with_opacity(0.38),
11774                );
11775            });
11776        }
11777
11778        // input_decorator_test.dart 'Material3 - InputDecoration label - for filled text field -
11779        // when field is hovered - label text has correct color'.
11780        #[test]
11781        fn filled_hovered_label_text_is_on_surface_variant() {
11782            test_widgets(|tester| {
11783                check_label_color(
11784                    tester,
11785                    BuildInputDecorator::new(filled_label()).is_hovering(true),
11786                    |theme| theme.color_scheme.on_surface_variant(),
11787                );
11788            });
11789        }
11790
11791        // input_decorator_test.dart 'Material3 - InputDecoration label - for filled text field -
11792        // when field is focused - label text has correct color'.
11793        #[test]
11794        fn filled_focused_label_text_is_primary() {
11795            test_widgets(|tester| {
11796                check_label_color(
11797                    tester,
11798                    BuildInputDecorator::new(filled_label()).is_focused(true),
11799                    |theme| theme.color_scheme.primary(),
11800                );
11801            });
11802        }
11803
11804        // input_decorator_test.dart 'Material3 - InputDecoration label - for filled text field -
11805        // when field is focused - label text has correct color when focused and hovered'.
11806        #[test]
11807        fn filled_focused_and_hovered_label_text_is_primary() {
11808            test_widgets(|tester| {
11809                check_label_color(
11810                    tester,
11811                    BuildInputDecorator::new(filled_label())
11812                        .is_focused(true)
11813                        .is_hovering(true),
11814                    |theme| theme.color_scheme.primary(),
11815                );
11816            });
11817        }
11818
11819        // input_decorator_test.dart 'Material3 - InputDecoration label - for filled text field -
11820        // when field is in error - label text has correct color'.
11821        #[test]
11822        fn filled_error_label_text_is_error() {
11823            test_widgets(|tester| {
11824                check_label_color(
11825                    tester,
11826                    BuildInputDecorator::new(filled_label().error_text(ERROR_TEXT)),
11827                    |theme| theme.color_scheme.error(),
11828                );
11829            });
11830        }
11831
11832        // input_decorator_test.dart 'Material3 - InputDecoration label - for filled text field -
11833        // when field is in error - label text has correct color when focused'.
11834        #[test]
11835        fn filled_focused_error_label_text_is_error() {
11836            test_widgets(|tester| {
11837                check_label_color(
11838                    tester,
11839                    BuildInputDecorator::new(filled_label().error_text(ERROR_TEXT))
11840                        .is_focused(true),
11841                    |theme| theme.color_scheme.error(),
11842                );
11843            });
11844        }
11845
11846        // input_decorator_test.dart 'Material3 - InputDecoration label - for filled text field -
11847        // when field is in error - label text has correct style when hovered'.
11848        #[test]
11849        fn filled_hovered_error_label_text_is_on_error_container() {
11850            test_widgets(|tester| {
11851                check_label_color(
11852                    tester,
11853                    BuildInputDecorator::new(filled_label().error_text(ERROR_TEXT))
11854                        .is_hovering(true),
11855                    |theme| theme.color_scheme.on_error_container(),
11856                );
11857            });
11858        }
11859
11860        // input_decorator_test.dart 'Material3 - InputDecoration label - for filled text field -
11861        // when field is in error - label text has correct style when focused and hovered'.
11862        #[test]
11863        fn filled_focused_and_hovered_error_label_text_is_error() {
11864            test_widgets(|tester| {
11865                check_label_color(
11866                    tester,
11867                    BuildInputDecorator::new(filled_label().error_text(ERROR_TEXT))
11868                        .is_focused(true)
11869                        .is_hovering(true),
11870                    |theme| theme.color_scheme.error(),
11871                );
11872            });
11873        }
11874
11875        // input_decorator_test.dart 'Material3 - InputDecoration label - for outlined text field -
11876        // label and input horizontal positions are M3 compliant in LTR'.
11877        #[test]
11878        fn outlined_label_and_input_start_at_the_padding_and_the_input_gap_in_ltr() {
11879            test_widgets(|tester| {
11880                pump(
11881                    tester,
11882                    BuildInputDecorator::new(
11883                        InputDecoration::new()
11884                            .border(OutlineInputBorder::new())
11885                            .label_text(LABEL_TEXT),
11886                    ),
11887                );
11888                assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, 56.0));
11889                let label_and_input_start = 12.0 + 4.0; // Content left padding + default input gap.
11890                assert_eq!(get_label_rect(tester).left, label_and_input_start);
11891                assert_eq!(get_input_rect(tester).left, label_and_input_start);
11892            });
11893        }
11894
11895        // input_decorator_test.dart 'Material3 - InputDecoration label - for outlined text field -
11896        // label and input horizontal positions are M3 compliant in RTL'.
11897        #[test]
11898        fn outlined_label_and_input_start_at_the_padding_and_the_input_gap_in_rtl() {
11899            test_widgets(|tester| {
11900                pump(
11901                    tester,
11902                    BuildInputDecorator::new(
11903                        InputDecoration::new()
11904                            .border(OutlineInputBorder::new())
11905                            .label_text(LABEL_TEXT),
11906                    )
11907                    .text_direction(TextDirection::Rtl),
11908                );
11909                assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, 56.0));
11910                let label_and_input_start = 12.0 + 4.0; // Content left padding + default input gap.
11911                assert_eq!(get_label_rect(tester).right, 800.0 - label_and_input_start);
11912                assert_eq!(get_input_rect(tester).right, 800.0 - label_and_input_start);
11913            });
11914        }
11915
11916        // input_decorator_test.dart 'Material3 - InputDecoration label - for outlined text field -
11917        // label and input horizontal positions can be adjusted in LTR'.
11918        #[test]
11919        fn outlined_label_and_input_start_at_a_custom_gap_padding_in_ltr() {
11920            test_widgets(|tester| {
11921                let custom_gap = 6.0;
11922                pump(
11923                    tester,
11924                    BuildInputDecorator::new(
11925                        InputDecoration::new()
11926                            .border(OutlineInputBorder::new().gap_padding(custom_gap))
11927                            .label_text(LABEL_TEXT),
11928                    ),
11929                );
11930                assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, 56.0));
11931                let label_and_input_start = 12.0 + custom_gap; // Content left padding + input gap.
11932                assert_eq!(get_label_rect(tester).left, label_and_input_start);
11933                assert_eq!(get_input_rect(tester).left, label_and_input_start);
11934            });
11935        }
11936
11937        // input_decorator_test.dart 'Material3 - InputDecoration label - for outlined text field -
11938        // label and input horizontal positions can be adjusted in RTL'.
11939        #[test]
11940        fn outlined_label_and_input_start_at_a_custom_gap_padding_in_rtl() {
11941            test_widgets(|tester| {
11942                let custom_gap = 6.0;
11943                pump(
11944                    tester,
11945                    BuildInputDecorator::new(
11946                        InputDecoration::new()
11947                            .border(OutlineInputBorder::new().gap_padding(custom_gap))
11948                            .label_text(LABEL_TEXT),
11949                    )
11950                    .text_direction(TextDirection::Rtl),
11951                );
11952                assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, 56.0));
11953                let label_and_input_start = 12.0 + custom_gap; // Content left padding + input gap.
11954                assert_eq!(get_label_rect(tester).right, 800.0 - label_and_input_start);
11955                assert_eq!(get_input_rect(tester).right, 800.0 - label_and_input_start);
11956            });
11957        }
11958
11959        // input_decorator_test.dart 'Material3 - InputDecoration label - for outlined text field -
11960        // when field is enabled - label text has correct style'.
11961        #[test]
11962        fn outlined_enabled_label_text_has_body_large_in_on_surface_variant() {
11963            test_widgets(|tester| {
11964                pump(tester, BuildInputDecorator::new(outlined_label()));
11965                let theme = decorator_theme(tester);
11966                // Current input decorator implementation forces line height to 1.0,
11967                // this is not compliant with M3 spec.
11968                let expected =
11969                    expected_label_style(&theme, theme.color_scheme.on_surface_variant());
11970                assert_eq!(get_label_style(tester), expected);
11971            });
11972        }
11973
11974        // input_decorator_test.dart 'Material3 - InputDecoration label - for outlined text field -
11975        // when field is disabled - label text has correct color'.
11976        #[test]
11977        fn outlined_disabled_label_text_is_on_surface_at_38_percent() {
11978            test_widgets(|tester| {
11979                check_label_color(
11980                    tester,
11981                    BuildInputDecorator::new(outlined_label().enabled(false)),
11982                    |theme| theme.color_scheme.on_surface().with_opacity(0.38),
11983                );
11984            });
11985        }
11986
11987        // input_decorator_test.dart 'Material3 - InputDecoration label - for outlined text field -
11988        // when field is hovered - label text has correct color'.
11989        #[test]
11990        fn outlined_hovered_label_text_is_on_surface_variant() {
11991            test_widgets(|tester| {
11992                check_label_color(
11993                    tester,
11994                    BuildInputDecorator::new(outlined_label()).is_hovering(true),
11995                    |theme| theme.color_scheme.on_surface_variant(),
11996                );
11997            });
11998        }
11999
12000        // input_decorator_test.dart 'Material3 - InputDecoration label - for outlined text field -
12001        // when field is focused - label text has correct color'.
12002        #[test]
12003        fn outlined_focused_label_text_is_primary() {
12004            test_widgets(|tester| {
12005                check_label_color(
12006                    tester,
12007                    BuildInputDecorator::new(outlined_label()).is_focused(true),
12008                    |theme| theme.color_scheme.primary(),
12009                );
12010            });
12011        }
12012
12013        // input_decorator_test.dart 'Material3 - InputDecoration label - for outlined text field -
12014        // when field is focused - label text has correct color when focused and hovered'.
12015        #[test]
12016        fn outlined_focused_and_hovered_label_text_is_primary() {
12017            test_widgets(|tester| {
12018                check_label_color(
12019                    tester,
12020                    BuildInputDecorator::new(outlined_label())
12021                        .is_focused(true)
12022                        .is_hovering(true),
12023                    |theme| theme.color_scheme.primary(),
12024                );
12025            });
12026        }
12027
12028        fn outlined_error_label() -> InputDecoration {
12029            InputDecoration::new()
12030                .border(OutlineInputBorder::new())
12031                .label_text(LABEL_TEXT)
12032                .error_text(ERROR_TEXT)
12033        }
12034
12035        // input_decorator_test.dart 'Material3 - InputDecoration label - for outlined text field -
12036        // when field is in error - label text has correct color'.
12037        #[test]
12038        fn outlined_error_label_text_is_error() {
12039            test_widgets(|tester| {
12040                check_label_color(
12041                    tester,
12042                    BuildInputDecorator::new(outlined_error_label()),
12043                    |theme| theme.color_scheme.error(),
12044                );
12045            });
12046        }
12047
12048        // input_decorator_test.dart 'Material3 - InputDecoration label - for outlined text field -
12049        // when field is in error - label text has correct color when focused'.
12050        #[test]
12051        fn outlined_focused_error_label_text_is_error() {
12052            test_widgets(|tester| {
12053                check_label_color(
12054                    tester,
12055                    BuildInputDecorator::new(outlined_error_label()).is_focused(true),
12056                    |theme| theme.color_scheme.error(),
12057                );
12058            });
12059        }
12060
12061        // input_decorator_test.dart 'Material3 - InputDecoration label - for outlined text field -
12062        // when field is in error - label text has correct color when hovered'.
12063        #[test]
12064        fn outlined_hovered_error_label_text_is_on_error_container() {
12065            test_widgets(|tester| {
12066                check_label_color(
12067                    tester,
12068                    BuildInputDecorator::new(outlined_error_label()).is_hovering(true),
12069                    |theme| theme.color_scheme.on_error_container(),
12070                );
12071            });
12072        }
12073
12074        // input_decorator_test.dart 'Material3 - InputDecoration label - for outlined text field -
12075        // when field is in error - label text has correct color when focused and hovered'.
12076        #[test]
12077        fn outlined_focused_and_hovered_error_label_text_is_error() {
12078            test_widgets(|tester| {
12079                check_label_color(
12080                    tester,
12081                    BuildInputDecorator::new(outlined_error_label())
12082                        .is_focused(true)
12083                        .is_hovering(true),
12084                    |theme| theme.color_scheme.error(),
12085                );
12086            });
12087        }
12088
12089        // input_decorator_test.dart 'Material3 - InputDecoration label - Label and input for
12090        // non-filled and non-outlined text field have no horizontal padding in LTR'.
12091        #[test]
12092        fn underlined_label_and_input_have_no_horizontal_padding_in_ltr() {
12093            test_widgets(|tester| {
12094                pump(
12095                    tester,
12096                    BuildInputDecorator::new(InputDecoration::new().label_text(LABEL_TEXT)),
12097                );
12098                assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, 56.0));
12099                assert_eq!(get_label_rect(tester).left, 0.0);
12100                assert_eq!(get_input_rect(tester).left, 0.0);
12101            });
12102        }
12103
12104        // input_decorator_test.dart 'Material3 - InputDecoration label - Label and input for
12105        // non-filled and non-outlined text field have no horizontal padding in RTL'.
12106        #[test]
12107        fn underlined_label_and_input_have_no_horizontal_padding_in_rtl() {
12108            test_widgets(|tester| {
12109                pump(
12110                    tester,
12111                    BuildInputDecorator::new(InputDecoration::new().label_text(LABEL_TEXT))
12112                        .text_direction(TextDirection::Rtl),
12113                );
12114                assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, 56.0));
12115                assert_eq!(get_label_rect(tester).right, 800.0);
12116                assert_eq!(get_input_rect(tester).right, 800.0);
12117            });
12118        }
12119
12120        fn style(color: Color) -> TextStyle {
12121            TextStyle::new().color(color).font_size(16.0)
12122        }
12123
12124        fn check_label_color_and_size(tester: &WidgetTester, expected: &TextStyle) {
12125            let label_style = get_label_style(tester);
12126            assert_eq!(color_of(&label_style), color_of(expected));
12127            assert_eq!(label_style.font_size, expected.font_size);
12128        }
12129
12130        // input_decorator_test.dart 'Material3 - InputDecoration label - floatingLabelStyle
12131        // overrides default style'.
12132        #[test]
12133        fn floating_label_style_overrides_the_default_style() {
12134            test_widgets(|tester| {
12135                let floating_label_style = style(Colors::INDIGO.primary());
12136                pump(
12137                    tester,
12138                    BuildInputDecorator::new(
12139                        InputDecoration::new()
12140                            .label_text(LABEL_TEXT)
12141                            .floating_label_style(floating_label_style.clone()),
12142                    )
12143                    .is_empty(true)
12144                    // Label appears floating above input field.
12145                    .is_focused(true),
12146                );
12147                check_label_color_and_size(tester, &floating_label_style);
12148            });
12149        }
12150
12151        // input_decorator_test.dart 'Material3 - InputDecoration label - floatingLabelStyle
12152        // defaults to labelStyle'.
12153        #[test]
12154        fn floating_label_style_defaults_to_label_style() {
12155            test_widgets(|tester| {
12156                let label_style = style(Colors::AMBER.primary());
12157                pump(
12158                    tester,
12159                    BuildInputDecorator::new(
12160                        InputDecoration::new()
12161                            .label_text(LABEL_TEXT)
12162                            .label_style(label_style.clone()),
12163                    )
12164                    .is_empty(true)
12165                    // Label appears floating above input field.
12166                    .is_focused(true),
12167                );
12168                check_label_color_and_size(tester, &label_style);
12169            });
12170        }
12171
12172        // input_decorator_test.dart 'Material3 - InputDecoration label - floatingLabelStyle takes
12173        // precedence over labelStyle'.
12174        #[test]
12175        fn floating_label_style_takes_precedence_over_label_style() {
12176            test_widgets(|tester| {
12177                let label_style = style(Colors::AMBER.primary());
12178                let floating_label_style = style(Colors::INDIGO.primary());
12179                pump(
12180                    tester,
12181                    BuildInputDecorator::new(
12182                        InputDecoration::new()
12183                            .label_text(LABEL_TEXT)
12184                            .label_style(label_style)
12185                            .floating_label_style(floating_label_style.clone()),
12186                    )
12187                    .is_empty(true)
12188                    // Label appears floating above input field.
12189                    .is_focused(true),
12190                );
12191                check_label_color_and_size(tester, &floating_label_style);
12192            });
12193        }
12194
12195        // input_decorator_test.dart 'Material3 - InputDecoration label -
12196        // InputDecorationThemeData.labelStyle overrides default style'.
12197        #[test]
12198        fn the_theme_label_style_overrides_the_default_style() {
12199            test_widgets(|tester| {
12200                let label_style = style(Colors::AMBER.primary());
12201                pump(
12202                    tester,
12203                    // Label appears inline, on top of the input field.
12204                    BuildInputDecorator::new(InputDecoration::new().label_text(LABEL_TEXT))
12205                        .is_empty(true)
12206                        .input_decoration_theme(
12207                            InputDecorationThemeData::new().label_style(label_style.clone()),
12208                        ),
12209                );
12210                assert_eq!(color_of(&get_label_style(tester)), color_of(&label_style));
12211            });
12212        }
12213
12214        // input_decorator_test.dart 'Material3 - InputDecoration label -
12215        // InputDecorationThemeData.floatingLabelStyle overrides default style'.
12216        #[test]
12217        fn the_theme_floating_label_style_overrides_the_default_style() {
12218            test_widgets(|tester| {
12219                let floating_label_style = style(Colors::INDIGO.primary());
12220                pump(
12221                    tester,
12222                    BuildInputDecorator::new(InputDecoration::new().label_text(LABEL_TEXT))
12223                        .is_empty(true)
12224                        // Label appears floating above input field.
12225                        .is_focused(true)
12226                        .input_decoration_theme(
12227                            InputDecorationThemeData::new()
12228                                .floating_label_style(floating_label_style.clone()),
12229                        ),
12230                );
12231                assert_eq!(
12232                    color_of(&get_label_style(tester)),
12233                    color_of(&floating_label_style)
12234                );
12235            });
12236        }
12237
12238        // input_decorator_test.dart 'Material3 - InputDecoration label - floatingLabelStyle is
12239        // always used when FloatingLabelBehavior.always'.
12240        #[test]
12241        fn floating_label_style_is_always_used_when_the_label_always_floats() {
12242            test_widgets(|tester| {
12243                let label_style = style(Colors::AMBER.primary());
12244                let floating_label_style = style(Colors::INDIGO.primary());
12245                let decoration = InputDecoration::new()
12246                    .label_text(LABEL_TEXT)
12247                    .label_style(label_style)
12248                    .floating_label_style(floating_label_style.clone())
12249                    .floating_label_behavior(FloatingLabelBehavior::Always);
12250
12251                pump(
12252                    tester,
12253                    BuildInputDecorator::new(decoration.clone()).is_empty(true),
12254                );
12255                check_label_color_and_size(tester, &floating_label_style);
12256
12257                // Focus the input decorator.
12258                tester.pump_widget(
12259                    BuildInputDecorator::new(decoration)
12260                        .is_empty(true)
12261                        .is_focused(true)
12262                        .build(),
12263                );
12264                check_label_color_and_size(tester, &floating_label_style);
12265            });
12266        }
12267
12268        // ----- Material3 - InputDecoration labelText layout / label layout -----
12269        //
12270        // Dart runs the same layout cases with `labelText` and with the `customLabel` widget; both
12271        // are `label_text` here, so each pair is one case below.
12272
12273        // input_decorator_test.dart 'Material3 - InputDecoration labelText layout - The label
12274        // appears above input' and 'Material3 - InputDecoration label layout - The label appears
12275        // above input'.
12276        #[test]
12277        fn the_label_appears_above_the_input() {
12278            test_widgets(|tester| {
12279                pump(
12280                    tester,
12281                    BuildInputDecorator::new(InputDecoration::new().label_text(LABEL_TEXT)),
12282                );
12283
12284                // Overall height for this InputDecorator is 56dp on mobile:
12285                //    8 - top padding
12286                //   12 - floating label (font size = 16 * 0.75, line height is forced to 1.0)
12287                //    4 - gap between label and input (this is not part of the M3 spec)
12288                //   24 - input text (font size = 16, line height = 1.5)
12289                //    8 - bottom padding
12290                assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, 56.0));
12291                assert_eq!(get_label_rect(tester).top, 8.0);
12292                assert_eq!(get_label_rect(tester).bottom, 20.0);
12293                assert_eq!(get_input_rect(tester).top, 24.0);
12294                assert_eq!(get_input_rect(tester).bottom, 48.0);
12295            });
12296        }
12297
12298        // input_decorator_test.dart 'Material3 - InputDecoration labelText layout - The label
12299        // appears within the input when there is no text content' and its label layout twin.
12300        #[test]
12301        fn the_label_appears_within_the_input_when_there_is_no_text_content() {
12302            test_widgets(|tester| {
12303                pump(
12304                    tester,
12305                    BuildInputDecorator::new(InputDecoration::new().label_text(LABEL_TEXT))
12306                        .is_empty(true),
12307                );
12308                assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, 56.0));
12309                // Label line height is forced to 1.0 and font size is 16.0,
12310                // the label should be vertically centered (20 pixels above and below).
12311                assert_eq!(get_label_rect(tester).top, 20.0);
12312                assert_eq!(get_label_rect(tester).bottom, 36.0);
12313            });
12314        }
12315
12316        fn large_label_rect(tester: &mut WidgetTester, decoration: InputDecoration) -> Rect {
12317            pump(tester, BuildInputDecorator::new(decoration).is_empty(true));
12318            let large = tester.element(find::by_widget_predicate(
12319                "a SizedBox 1000 wide",
12320                |_app, widget| {
12321                    downcast_widget::<SizedBox>(widget)
12322                        .is_some_and(|sized| sized.width == Some(1000.0))
12323                },
12324            ));
12325            tester.get_rect(large)
12326        }
12327
12328        // input_decorator_test.dart 'Material3 - InputDecoration labelText layout - When the label
12329        // appears within the input its padding is correct'.
12330        #[test]
12331        fn a_label_within_the_input_fills_the_space_between_the_paddings() {
12332            test_widgets(|tester| {
12333                // Define a label larger than the available decorator, the label will fill
12334                // all the available space (decorator width minus padding and affixes).
12335                let large_label = || SizedBox::new().width(1000.0).height(16.0).into_widget();
12336
12337                // For filled and/or outlined decoration, the horizontal padding is 16.
12338                let horizontal_padding = 16.0;
12339                let rect = large_label_rect(
12340                    tester,
12341                    InputDecoration::new().filled(true).label(large_label()),
12342                );
12343                assert_eq!(rect.left, horizontal_padding);
12344                assert_eq!(rect.right, 800.0 - horizontal_padding);
12345
12346                // Outlined decorator.
12347                let rect = large_label_rect(
12348                    tester,
12349                    InputDecoration::new()
12350                        .border(OutlineInputBorder::new())
12351                        .label(large_label()),
12352                );
12353                assert_eq!(rect.left, horizontal_padding);
12354                assert_eq!(rect.right, 800.0 - horizontal_padding);
12355
12356                // Rebuild with affixes.
12357                let rect = large_label_rect(
12358                    tester,
12359                    InputDecoration::new()
12360                        .filled(true)
12361                        .label(large_label())
12362                        .suffix_icon(Icon::new(Some(Icons::align_horizontal_left_sharp())))
12363                        .prefix_icon(Icon::new(Some(Icons::align_horizontal_right_sharp()))),
12364                );
12365
12366                // When suffixIcon and/or prefixIcon are set, the corresponding horizontal
12367                // padding is 52 (48 for the icon + 4 input gap based on M3 spec).
12368                let affixes_horizontal_padding = 52.0;
12369                assert_eq!(rect.left, affixes_horizontal_padding);
12370                assert_eq!(rect.right, 800.0 - affixes_horizontal_padding);
12371
12372                // Outlined decorator.
12373                let rect = large_label_rect(
12374                    tester,
12375                    InputDecoration::new()
12376                        .border(OutlineInputBorder::new())
12377                        .label(large_label())
12378                        .suffix_icon(Icon::new(Some(Icons::align_horizontal_left_sharp())))
12379                        .prefix_icon(Icon::new(Some(Icons::align_horizontal_right_sharp()))),
12380                );
12381                assert_eq!(rect.left, affixes_horizontal_padding);
12382                assert_eq!(rect.right, 800.0 - affixes_horizontal_padding);
12383            });
12384        }
12385
12386        // input_decorator_test.dart 'Material3 - InputDecoration labelText layout - The label
12387        // appears above the input when there is no content and floatingLabelBehavior is always'
12388        // and its label layout twin.
12389        #[test]
12390        fn an_always_floating_label_appears_above_an_empty_input() {
12391            test_widgets(|tester| {
12392                pump(
12393                    tester,
12394                    BuildInputDecorator::new(
12395                        InputDecoration::new()
12396                            .label_text(LABEL_TEXT)
12397                            .floating_label_behavior(FloatingLabelBehavior::Always),
12398                    )
12399                    .is_empty(true),
12400                );
12401                assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, 56.0));
12402                assert_eq!(get_label_rect(tester).top, 8.0);
12403                assert_eq!(get_label_rect(tester).bottom, 20.0);
12404            });
12405        }
12406
12407        // input_decorator_test.dart 'Material3 - InputDecoration labelText layout - The label
12408        // appears within the input text when there is content and floatingLabelBehavior is never'
12409        // and its label layout twin.
12410        #[test]
12411        fn a_never_floating_label_appears_within_an_input_with_content() {
12412            test_widgets(|tester| {
12413                pump(
12414                    tester,
12415                    BuildInputDecorator::new(
12416                        InputDecoration::new()
12417                            .label_text(LABEL_TEXT)
12418                            .floating_label_behavior(FloatingLabelBehavior::Never),
12419                    ),
12420                );
12421                assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, 56.0));
12422                // Label line height is forced to 1.0 and font size is 16.0,
12423                // the label should be vertically centered (20 pixels above and below).
12424                assert_eq!(get_label_rect(tester).top, 20.0);
12425                assert_eq!(get_label_rect(tester).bottom, 36.0);
12426            });
12427        }
12428
12429        // input_decorator_test.dart 'Material3 - InputDecoration labelText layout - Ambient theme
12430        // floatingLabelBehavior is used'.
12431        #[test]
12432        fn the_ambient_theme_floating_label_behavior_is_used() {
12433            test_widgets(|tester| {
12434                pump(
12435                    tester,
12436                    BuildInputDecorator::new(InputDecoration::new().label_text(LABEL_TEXT))
12437                        .input_decoration_theme(
12438                            InputDecorationThemeData::new()
12439                                .floating_label_behavior(FloatingLabelBehavior::Never),
12440                        ),
12441                );
12442                assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, 56.0));
12443                // Label line height is forced to 1.0 and font size is 16.0,
12444                // the label should be vertically centered (20 pixels above and below).
12445                assert_eq!(get_label_rect(tester).top, 20.0);
12446                assert_eq!(get_label_rect(tester).bottom, 36.0);
12447            });
12448        }
12449
12450        // input_decorator_test.dart 'Material3 - InputDecoration labelText layout - Floating label
12451        // animation duration and curve' and its label layout twin.
12452        #[test]
12453        fn the_floating_label_animates_for_167_ms_along_fast_out_slow_in() {
12454            test_widgets(|tester| {
12455                let build = |is_focused: bool| {
12456                    BuildInputDecorator::new(
12457                        InputDecoration::new()
12458                            .label_text(LABEL_TEXT)
12459                            .floating_label_behavior(FloatingLabelBehavior::Auto),
12460                    )
12461                    .is_empty(true)
12462                    .is_focused(is_focused)
12463                    .build()
12464                };
12465
12466                tester.pump_widget(build(false));
12467                assert_eq!(get_label_rect(tester).top, 20.0);
12468
12469                // The label animates upwards and scales down.
12470                // The animation duration is 167ms and the curve is fastOutSlowIn.
12471                tester.pump_widget(build(true));
12472                tester.pump_by(ms(42));
12473                assert_more_or_less_equals_within(get_label_rect(tester).top, 17.09, 0.5);
12474                tester.pump_by(ms(42));
12475                assert_more_or_less_equals_within(get_label_rect(tester).top, 10.66, 0.5);
12476                tester.pump_by(ms(42));
12477                assert_more_or_less_equals_within(get_label_rect(tester).top, 8.47, 0.5);
12478                tester.pump_by(ms(41));
12479                assert_eq!(get_label_rect(tester).top, 8.0);
12480
12481                // If the animation changes direction without first reaching the
12482                // AnimationStatus.completed or AnimationStatus.dismissed status,
12483                // the CurvedAnimation stays on the same curve in the opposite direction.
12484                // The pumpAndSettle is used to prevent this behavior.
12485                tester.pump_and_settle();
12486
12487                // The label animates downwards and scales up.
12488                // The animation duration is 167ms and the curve is fastOutSlowIn.
12489                tester.pump_widget(build(false));
12490                tester.pump_by(ms(42));
12491                assert_more_or_less_equals_within(get_label_rect(tester).top, 10.90, 0.5);
12492                tester.pump_by(ms(42));
12493                assert_more_or_less_equals_within(get_label_rect(tester).top, 17.34, 0.5);
12494                tester.pump_by(ms(42));
12495                assert_more_or_less_equals_within(get_label_rect(tester).top, 19.69, 0.5);
12496                tester.pump_by(ms(41));
12497                assert_eq!(get_label_rect(tester).top, 20.0);
12498            });
12499        }
12500
12501        // input_decorator_test.dart 'Material3 - InputDecoration labelText layout - InputDecorator
12502        // withdraws label when not empty or focused'.
12503        #[test]
12504        fn the_label_withdraws_when_not_empty_or_focused_while_enabled() {
12505            test_widgets(|tester| {
12506                let mut pump_decorator = |focused: bool, enabled: bool, empty: bool| {
12507                    tester.pump_widget(
12508                        BuildInputDecorator::new(
12509                            InputDecoration::new()
12510                                .label_text("Label")
12511                                .enabled(enabled)
12512                                .filled(false)
12513                                .focused_border(OutlineInputBorder::new())
12514                                .disabled_border(OutlineInputBorder::new())
12515                                .border(OutlineInputBorder::new()),
12516                        )
12517                        .is_empty(empty)
12518                        .is_focused(focused)
12519                        .build(),
12520                    );
12521                    tester.pump_by(K_TRANSITION_DURATION);
12522                    let rect = tester.get_rect(find::text("Label"));
12523                    (rect.top_left(), rect.size())
12524                };
12525
12526                let label_size = Size::new(82.5, 16.0);
12527                let floating = (Offset::new(16.0, -5.5), label_size * 0.75);
12528                let inline = (Offset::new(16.0, 20.0), label_size);
12529                assert_eq!(pump_decorator(false, true, true), inline);
12530                assert_eq!(pump_decorator(false, true, false), floating);
12531                assert_eq!(pump_decorator(true, true, true), floating);
12532                assert_eq!(pump_decorator(true, true, false), floating);
12533                assert_eq!(pump_decorator(false, false, true), inline);
12534                assert_eq!(pump_decorator(false, false, false), floating);
12535                // Focused and disabled happens with NavigationMode.directional.
12536                assert_eq!(pump_decorator(true, false, true), inline);
12537                assert_eq!(pump_decorator(true, false, false), floating);
12538            });
12539        }
12540
12541        // input_decorator_test.dart 'Material3 - InputDecoration labelText layout - InputDecorator
12542        // floating label width scales when focused'. Dart reads the width from the clip the
12543        // label's ellipsized `Text` paints; here it is the label's laid out width.
12544        #[test]
12545        fn the_floating_label_width_scales_up_when_focused() {
12546            test_widgets(|tester| {
12547                let long_string_a = "A".repeat(200);
12548                let long_string_b = "B".repeat(200);
12549                let build = |text: &str, is_focused: bool| {
12550                    Center::new()
12551                        .child(
12552                            SizedBox::square(Some(100.0)).child(
12553                                BuildInputDecorator::new(InputDecoration::new().label_text(text))
12554                                    .is_empty(true)
12555                                    .is_focused(is_focused)
12556                                    .build(),
12557                            ),
12558                        )
12559                        .into_widget()
12560                };
12561                let label_size =
12562                    |tester: &WidgetTester, text: &str| tester.get_size(find::text(text));
12563
12564                tester.pump_widget(build(&long_string_a, false));
12565                assert_eq!(label_size(tester, &long_string_a), Size::new(100.0, 16.0));
12566
12567                tester.pump_widget(build(&long_string_b, true));
12568                tester.pump_by(K_TRANSITION_DURATION);
12569                let size = label_size(tester, &long_string_b);
12570                // _kFinalLabelScale = 0.75
12571                assert!((size.width() - 100.0 / 0.75).abs() < 1e-5, "{size:?}");
12572                assert_eq!(size.height(), 16.0);
12573            });
12574        }
12575
12576        // input_decorator_test.dart 'Material3 - InputDecoration labelText layout - InputDecorator
12577        // floating label Y coordinate'.
12578        #[test]
12579        fn the_floating_label_is_centred_on_a_wide_outline() {
12580            test_widgets(|tester| {
12581                pump(
12582                    tester,
12583                    BuildInputDecorator::new(
12584                        InputDecoration::new()
12585                            .label_text(LABEL_TEXT)
12586                            .enabled_border(OutlineInputBorder::new().border_side(BorderSide {
12587                                width: 4.0,
12588                                ..BorderSide::default()
12589                            }))
12590                            .floating_label_behavior(FloatingLabelBehavior::Always),
12591                    )
12592                    .is_empty(true),
12593                );
12594                tester.pump_by(K_TRANSITION_DURATION);
12595
12596                // floatingLabelHeight = 12 (font size 16dps * 0.75 = 12)
12597                // labelY = -floatingLabelHeight/2 + borderWidth/2
12598                assert_eq!(get_label_rect(tester).top, -4.0);
12599            });
12600        }
12601
12602        fn density_frames(
12603            tester: &mut WidgetTester,
12604            visual_density: VisualDensity,
12605            height: f64,
12606            inline_label: (f64, f64),
12607            floating_label: (f64, f64),
12608            content: (f64, f64),
12609        ) {
12610            let decorator = |is_empty: bool, is_focused: bool| {
12611                BuildInputDecorator::new(
12612                    InputDecoration::new()
12613                        .label_text(LABEL_TEXT)
12614                        .hint_text(HINT_TEXT),
12615                )
12616                .is_empty(is_empty)
12617                .is_focused(is_focused)
12618                .visual_density(visual_density)
12619                .build()
12620            };
12621            tester.pump_widget(decorator(true, false));
12622
12623            assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, height));
12624
12625            // The decorator is empty, label is not floating and is vertically centered.
12626            assert_eq!(get_label_rect(tester).top, inline_label.0);
12627            assert_eq!(get_label_rect(tester).bottom, inline_label.1);
12628            assert_eq!(get_hint_opacity(tester), 0.0);
12629            assert_eq!(get_border_bottom(tester), height);
12630            assert_eq!(get_border_weight(tester), 1.0);
12631
12632            // When the decorator is focused, label moves upwards, hint is visible (opacity 1.0).
12633            tester.pump_widget(decorator(true, true));
12634            tester.pump_by(K_TRANSITION_DURATION);
12635
12636            // The decorator is empty and focused, label and hint are visible.
12637            assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, height));
12638            assert_eq!(get_label_rect(tester).top, floating_label.0);
12639            assert_eq!(get_label_rect(tester).bottom, floating_label.1);
12640            assert_eq!(get_hint_rect(tester).top, content.0);
12641            assert_eq!(get_hint_rect(tester).bottom, content.1);
12642            assert_eq!(get_hint_opacity(tester), 1.0);
12643            assert_eq!(get_border_bottom(tester), height);
12644            assert_eq!(get_border_weight(tester), 2.0);
12645
12646            tester.pump_widget(decorator(false, true));
12647            tester.pump_by(K_TRANSITION_DURATION);
12648
12649            // The decorator is focused and not empty, label and input are visible.
12650            assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, height));
12651            assert_eq!(get_label_rect(tester).top, floating_label.0);
12652            assert_eq!(get_label_rect(tester).bottom, floating_label.1);
12653            assert_eq!(get_input_rect(tester).top, content.0);
12654            assert_eq!(get_input_rect(tester).bottom, content.1);
12655            assert_eq!(get_hint_opacity(tester), 0.0);
12656            assert_eq!(get_border_bottom(tester), height);
12657            assert_eq!(get_border_weight(tester), 2.0);
12658        }
12659
12660        // input_decorator_test.dart 'Material3 - InputDecoration labelText layout - InputDecorator
12661        // respects reduced theme visualDensity'.
12662        #[test]
12663        fn the_decorator_respects_a_reduced_theme_visual_density() {
12664            test_widgets(|tester| {
12665                // Overall height for this InputDecorator is 48dp:
12666                //    4 - top padding (8 minus 4 due to reduced visual density)
12667                //   12 - floating label (font size = 16 * 0.75, line height is forced to 1.0)
12668                //    4 - gap between label and input (this is not part of the M3 spec)
12669                //   24 - input text (font size = 16, line height = 1.5)
12670                //    4 - bottom padding (8 minus 4 due to reduced visual density)
12671                density_frames(
12672                    tester,
12673                    VisualDensity::COMPACT,
12674                    48.0,
12675                    (16.0, 32.0),
12676                    (4.0, 16.0),
12677                    (20.0, 44.0),
12678                );
12679            });
12680        }
12681
12682        // input_decorator_test.dart 'Material3 - InputDecoration labelText layout - InputDecorator
12683        // respects increased theme visualDensity'.
12684        #[test]
12685        fn the_decorator_respects_an_increased_theme_visual_density() {
12686            test_widgets(|tester| {
12687                // Overall height for this InputDecorator is 64dp:
12688                //   12 - top padding (8 plus 4 due to increased visual density)
12689                //   12 - floating label (font size = 16 * 0.75, line height is forced to 1.0)
12690                //    4 - gap between label and input (this is not part of the M3 spec)
12691                //   24 - input text (font size = 16, line height = 1.5)
12692                //   12 - bottom padding (8 plus 4 due to increased visual density)
12693                density_frames(
12694                    tester,
12695                    VisualDensity::new(2.0, 2.0),
12696                    64.0,
12697                    (24.0, 40.0),
12698                    (12.0, 24.0),
12699                    (28.0, 52.0),
12700                );
12701            });
12702        }
12703
12704        // input_decorator_test.dart 'Material3 - InputDecoration label layout -
12705        // InputDecorationThemeData.floatingLabelStyle overrides label widget styles when the widget
12706        // is a text widget (focused)'.
12707        #[test]
12708        fn the_theme_floating_label_style_reaches_a_text_label_widget() {
12709            test_widgets(|tester| {
12710                let floating_label_style = TextStyle::new()
12711                    .font_size(16.0)
12712                    .merge(Some(&TextStyle::new().color(Colors::INDIGO.primary())));
12713                pump(
12714                    tester,
12715                    BuildInputDecorator::new(InputDecoration::new().label(Text::new("label")))
12716                        .is_empty(true)
12717                        // Label appears floating above input field.
12718                        .is_focused(true)
12719                        .input_decoration_theme(
12720                            InputDecorationThemeData::new()
12721                                .floating_label_style(floating_label_style.clone()),
12722                        ),
12723                );
12724                // Verify that the styles were passed along.
12725                assert_eq!(
12726                    color_of(&get_label_style(tester)),
12727                    color_of(&floating_label_style)
12728                );
12729            });
12730        }
12731
12732        // input_decorator_test.dart 'Material3 - InputDecoration label layout -
12733        // InputDecorationThemeData.labelStyle overrides label widget styles when the widget is a
12734        // text widget'.
12735        #[test]
12736        fn the_theme_label_style_reaches_a_text_label_widget() {
12737            test_widgets(|tester| {
12738                let label_style = TextStyle::new()
12739                    .font_size(16.0)
12740                    .merge(Some(&TextStyle::new().color(Colors::PURPLE.primary())));
12741                pump(
12742                    tester,
12743                    // Label appears inline, on top of the input field.
12744                    BuildInputDecorator::new(InputDecoration::new().label(Text::new("label")))
12745                        .is_empty(true)
12746                        .input_decoration_theme(
12747                            InputDecorationThemeData::new().label_style(label_style.clone()),
12748                        ),
12749                );
12750                // Verify that the styles were passed along.
12751                assert_eq!(color_of(&get_label_style(tester)), color_of(&label_style));
12752            });
12753        }
12754
12755        // ----- Material3 - InputDecoration hint -----
12756
12757        /// The decoration of a hint case: filled or outlined, with or without a label, the hint
12758        /// and label as texts.
12759        fn hint_decoration(outlined: bool, with_label: bool) -> InputDecoration {
12760            let mut decoration = InputDecoration::new().hint_text(HINT_TEXT);
12761            decoration = if outlined {
12762                decoration.border(OutlineInputBorder::new())
12763            } else {
12764                decoration.filled(true)
12765            };
12766            if with_label {
12767                decoration = decoration.label_text(LABEL_TEXT);
12768            }
12769            decoration
12770        }
12771
12772        /// The decoration of a hint style case, with Dart's strings.
12773        fn hint_style_decoration(outlined: bool, with_label: bool) -> InputDecoration {
12774            let mut decoration = InputDecoration::new().hint_text(HINT_TEXT);
12775            decoration = if outlined {
12776                decoration.border(OutlineInputBorder::new())
12777            } else {
12778                decoration.filled(true)
12779            };
12780            if with_label {
12781                decoration = decoration.label_text(LABEL_TEXT);
12782            }
12783            decoration
12784        }
12785
12786        /// One "hint and input align vertically" case.
12787        fn check_hint_alignment(
12788            tester: &mut WidgetTester,
12789            decorator: BuildInputDecorator,
12790            container_height: f64,
12791            input: (f64, f64),
12792            hint_opacity: f64,
12793        ) {
12794            pump(tester, decorator);
12795            assert_eq!(get_container_rect(tester).height(), container_height);
12796            assert_eq!(get_input_rect(tester).top, input.0);
12797            assert_eq!(get_input_rect(tester).bottom, input.1);
12798            assert_eq!(get_hint_rect(tester).top, get_input_rect(tester).top);
12799            assert_eq!(get_hint_rect(tester).bottom, get_input_rect(tester).bottom);
12800            assert_eq!(get_hint_opacity(tester), hint_opacity);
12801        }
12802
12803        /// One "hint has correct style when visible" case.
12804        fn check_hint_style(
12805            tester: &mut WidgetTester,
12806            decorator: BuildInputDecorator,
12807            expected_color: fn(&ThemeData) -> Color,
12808        ) {
12809            pump(tester, decorator);
12810            // Hint is visible because decorator is empty.
12811            assert_eq!(get_hint_opacity(tester), 1.0);
12812            let theme = decorator_theme(tester);
12813            let expected_style = theme
12814                .text_theme
12815                .body_large
12816                .clone()
12817                .expect("bodyLarge")
12818                .copy_with()
12819                .color(expected_color(&theme));
12820            assert_eq!(get_hint_style(tester), expected_style);
12821        }
12822
12823        fn on_surface_variant(theme: &ThemeData) -> Color {
12824            theme.color_scheme.on_surface_variant()
12825        }
12826
12827        fn disabled_on_surface(theme: &ThemeData) -> Color {
12828            theme.color_scheme.on_surface().with_opacity(0.38)
12829        }
12830
12831        /// Declares the "hint and input align vertically" cases of one decoration kind.
12832        macro_rules! hint_alignment_cases {
12833        ($outlined:expr, $with_label:expr, $height:expr, $input:expr,
12834         $($name:ident: $dart:literal, |$d:ident| $decoration:expr, |$b:ident| $builder:expr,
12835            $opacity:expr;)*) => {
12836            $(
12837                #[doc = concat!("input_decorator_test.dart '", $dart, "'.")]
12838                #[test]
12839                fn $name() {
12840                    test_widgets(|tester| {
12841                        let $d = hint_decoration($outlined, $with_label);
12842                        let $b = BuildInputDecorator::new($decoration);
12843                        check_hint_alignment(tester, $builder, $height, $input, $opacity);
12844                    });
12845                }
12846            )*
12847        };
12848    }
12849
12850        // Overall height for this InputDecorator is 48dp on mobile:
12851        //   12 - Top padding
12852        //   24 - Input and hint (font size = 16, line height = 1.5)
12853        //   12 - Bottom padding
12854        hint_alignment_cases! { false, false, 48.0, (12.0, 36.0),
12855            filled_enabled_empty_hint_aligns_with_the_input_and_shows:
12856                "hint - for filled text field without label - when field is enabled - hint and input align vertically when decorator is empty",
12857                |d| d, |b| b.is_empty(true), 1.0;
12858            filled_enabled_hint_aligns_with_a_non_empty_input_and_hides:
12859                "hint - for filled text field without label - when field is enabled - hint and input align vertically when decorator is not empty",
12860                |d| d, |b| b, 0.0;
12861            filled_disabled_empty_hint_aligns_with_the_input_and_shows:
12862                "hint - for filled text field without label - when field is disabled - hint and input align vertically when decorator is empty",
12863                |d| d.enabled(false), |b| b.is_empty(true), 1.0;
12864            filled_disabled_hint_aligns_with_a_non_empty_input_and_hides:
12865                "hint - for filled text field without label - when field is disabled - hint and input align vertically when decorator is not empty",
12866                |d| d.enabled(false), |b| b, 0.0;
12867            filled_hovered_empty_hint_aligns_with_the_input_and_shows:
12868                "hint - for filled text field without label - when field is hovered - hint and input align vertically when decorator is empty",
12869                |d| d, |b| b.is_hovering(true).is_empty(true), 1.0;
12870            filled_hovered_hint_aligns_with_a_non_empty_input_and_hides:
12871                "hint - for filled text field without label - when field is hovered - hint and input align vertically when decorator is not empty",
12872                |d| d, |b| b.is_hovering(true), 0.0;
12873            filled_focused_empty_hint_aligns_with_the_input_and_shows:
12874                "hint - for filled text field without label - when field is focused - hint and input align vertically when decorator is empty",
12875                |d| d, |b| b.is_focused(true).is_empty(true), 1.0;
12876            filled_focused_hint_aligns_with_a_non_empty_input_and_hides:
12877                "hint - for filled text field without label - when field is focused - hint and input align vertically when decorator is not empty",
12878                |d| d, |b| b.is_focused(true), 0.0;
12879            filled_error_empty_hint_aligns_with_the_input_and_shows:
12880                "hint - for filled text field without label - when field is in error - hint and input align vertically when decorator is empty",
12881                |d| d.error_text(ERROR_TEXT), |b| b.is_empty(true), 1.0;
12882            filled_error_hint_aligns_with_a_non_empty_input_and_hides:
12883                "hint - for filled text field without label - when field is in error - hint and input align vertically when decorator is not empty",
12884                |d| d.error_text(ERROR_TEXT), |b| b, 0.0;
12885        }
12886
12887        // Overall height for this InputDecorator is 56dp on mobile:
12888        //    8 - Top padding
12889        //   12 - Floating label (font size = 16 * 0.75, line height is forced to 1.0)
12890        //    4 - Gap between label and input (this is not part of the M3 spec)
12891        //   24 - Input/Hint (font size = 16, line height = 1.5)
12892        //    8 - Bottom padding
12893        hint_alignment_cases! { false, true, 56.0, (24.0, 48.0),
12894            filled_labelled_enabled_empty_hint_aligns_with_the_input_and_hides:
12895                "hint - for filled text field with label - when field is enabled - hint and input align vertically when decorator is empty",
12896                |d| d, |b| b.is_empty(true), 0.0;
12897            filled_labelled_enabled_hint_aligns_with_a_non_empty_input_and_hides:
12898                "hint - for filled text field with label - when field is enabled - hint and input align vertically when decorator is not empty",
12899                |d| d, |b| b, 0.0;
12900            filled_labelled_disabled_empty_hint_aligns_with_the_input_and_hides:
12901                "hint - for filled text field with label - when field is disabled - hint and input align vertically when decorator is empty",
12902                |d| d.enabled(false), |b| b.is_empty(true), 0.0;
12903            filled_labelled_disabled_hint_aligns_with_a_non_empty_input_and_hides:
12904                "hint - for filled text field with label - when field is disabled - hint and input align vertically when decorator is not empty",
12905                |d| d.enabled(false), |b| b, 0.0;
12906            filled_labelled_hovered_empty_hint_aligns_with_the_input_and_hides:
12907                "hint - for filled text field with label - when field is hovered - hint and input align vertically when decorator is empty",
12908                |d| d, |b| b.is_hovering(true).is_empty(true), 0.0;
12909            filled_labelled_hovered_hint_aligns_with_a_non_empty_input_and_hides:
12910                "hint - for filled text field with label - when field is hovered - hint and input align vertically when decorator is not empty",
12911                |d| d, |b| b.is_hovering(true), 0.0;
12912            filled_labelled_focused_empty_hint_aligns_with_the_input_and_shows:
12913                "hint - for filled text field with label - when field is focused - hint and input align vertically when decorator is empty",
12914                |d| d, |b| b.is_focused(true).is_empty(true), 1.0;
12915            filled_labelled_focused_hint_aligns_with_a_non_empty_input_and_hides:
12916                "hint - for filled text field with label - when field is focused - hint and input align vertically when decorator is not empty",
12917                |d| d, |b| b.is_focused(true), 0.0;
12918            filled_labelled_error_empty_hint_aligns_with_the_input_and_hides:
12919                "hint - for filled text field with label - when field is in error - hint and input align vertically when decorator is empty",
12920                |d| d.error_text(ERROR_TEXT), |b| b.is_empty(true), 0.0;
12921            filled_labelled_error_hint_aligns_with_a_non_empty_input_and_hides:
12922                "hint - for filled text field with label - when field is in error - hint and input align vertically when decorator is not empty",
12923                |d| d.error_text(ERROR_TEXT), |b| b, 0.0;
12924        }
12925
12926        // Overall height for this InputDecorator is 56dp on mobile:
12927        //   16 - Top padding
12928        //   24 - Input and hint (font size = 16, line height = 1.5)
12929        //   16 - Bottom padding
12930        hint_alignment_cases! { true, false, 56.0, (16.0, 40.0),
12931            outlined_enabled_empty_hint_aligns_with_the_input_and_shows:
12932                "hint - for outlined text field without label - when field is enabled - hint and input align vertically when decorator is empty",
12933                |d| d, |b| b.is_empty(true), 1.0;
12934            outlined_enabled_hint_aligns_with_a_non_empty_input_and_hides:
12935                "hint - for outlined text field without label - when field is enabled - hint and input align vertically when decorator is not empty",
12936                |d| d, |b| b, 0.0;
12937            outlined_disabled_empty_hint_aligns_with_the_input_and_shows:
12938                "hint - for outlined text field without label - when field is disabled - hint and input align vertically when decorator is empty",
12939                |d| d.enabled(false), |b| b.is_empty(true), 1.0;
12940            outlined_disabled_hint_aligns_with_a_non_empty_input_and_hides:
12941                "hint - for outlined text field without label - when field is disabled - hint and input align vertically when decorator is not empty",
12942                |d| d.enabled(false), |b| b, 0.0;
12943            outlined_hovered_empty_hint_aligns_with_the_input_and_shows:
12944                "hint - for outlined text field without label - when field is hovered - hint and input align vertically when decorator is empty",
12945                |d| d, |b| b.is_hovering(true).is_empty(true), 1.0;
12946            outlined_hovered_hint_aligns_with_a_non_empty_input_and_hides:
12947                "hint - for outlined text field without label - when field is hovered - hint and input align vertically when decorator is not empty",
12948                |d| d, |b| b.is_hovering(true), 0.0;
12949            outlined_focused_empty_hint_aligns_with_the_input_and_shows:
12950                "hint - for outlined text field without label - when field is focused - hint and input align vertically when decorator is empty",
12951                |d| d, |b| b.is_focused(true).is_empty(true), 1.0;
12952            outlined_focused_hint_aligns_with_a_non_empty_input_and_hides:
12953                "hint - for outlined text field without label - when field is focused - hint and input align vertically when decorator is not empty",
12954                |d| d, |b| b.is_focused(true), 0.0;
12955            outlined_error_empty_hint_aligns_with_the_input_and_shows:
12956                "hint - for outlined text field without label - when field is in error - hint and input align vertically when decorator is empty",
12957                |d| d.error_text(ERROR_TEXT), |b| b.is_empty(true), 1.0;
12958            outlined_error_hint_aligns_with_a_non_empty_input_and_hides:
12959                "hint - for outlined text field without label - when field is in error - hint and input align vertically when decorator is not empty",
12960                |d| d.error_text(ERROR_TEXT), |b| b, 0.0;
12961        }
12962
12963        // Overall height for this InputDecorator is 56dp on mobile:
12964        //   16 - Top padding
12965        //   24 - Input and hint (font size = 16, line height = 1.5)
12966        //   16 - Bottom padding
12967        hint_alignment_cases! { true, true, 56.0, (16.0, 40.0),
12968            outlined_labelled_enabled_empty_hint_aligns_with_the_input_and_hides:
12969                "hint - for outlined text field with label - when field is enabled - hint and input align vertically when decorator is empty",
12970                |d| d, |b| b.is_empty(true), 0.0;
12971            outlined_labelled_enabled_hint_aligns_with_a_non_empty_input_and_hides:
12972                "hint - for outlined text field with label - when field is enabled - hint and input align vertically when decorator is not empty",
12973                |d| d, |b| b, 0.0;
12974            outlined_labelled_disabled_empty_hint_aligns_with_the_input_and_hides:
12975                "hint - for outlined text field with label - when field is disabled - hint and input align vertically when decorator is empty",
12976                |d| d.enabled(false), |b| b.is_empty(true), 0.0;
12977            outlined_labelled_disabled_hint_aligns_with_a_non_empty_input_and_hides:
12978                "hint - for outlined text field with label - when field is disabled - hint and input align vertically when decorator is not empty",
12979                |d| d.enabled(false), |b| b, 0.0;
12980            outlined_labelled_hovered_empty_hint_aligns_with_the_input_and_hides:
12981                "hint - for outlined text field with label - when field is hovered - hint and input align vertically when decorator is empty",
12982                |d| d, |b| b.is_hovering(true).is_empty(true), 0.0;
12983            outlined_labelled_hovered_hint_aligns_with_a_non_empty_input_and_hides:
12984                "hint - for outlined text field with label - when field is hovered - hint and input align vertically when decorator is not empty",
12985                |d| d, |b| b.is_hovering(true), 0.0;
12986            outlined_labelled_focused_empty_hint_aligns_with_the_input_and_shows:
12987                "hint - for outlined text field with label - when field is focused - hint and input align vertically when decorator is empty",
12988                |d| d, |b| b.is_focused(true).is_empty(true), 1.0;
12989            outlined_labelled_focused_hint_aligns_with_a_non_empty_input_and_hides:
12990                "hint - for outlined text field with label - when field is focused - hint and input align vertically when decorator is not empty",
12991                |d| d, |b| b.is_focused(true), 0.0;
12992            outlined_labelled_error_empty_hint_aligns_with_the_input_and_hides:
12993                "hint - for outlined text field with label - when field is in error - hint and input align vertically when decorator is empty",
12994                |d| d.error_text(ERROR_TEXT), |b| b.is_empty(true), 0.0;
12995            outlined_labelled_error_hint_aligns_with_a_non_empty_input_and_hides:
12996                "hint - for outlined text field with label - when field is in error - hint and input align vertically when decorator is not empty",
12997                |d| d.error_text(ERROR_TEXT), |b| b, 0.0;
12998        }
12999
13000        /// Declares the "hint has correct style when visible" cases.
13001        macro_rules! hint_style_cases {
13002        ($($name:ident: $dart:literal, $outlined:expr, $with_label:expr,
13003            |$d:ident| $decoration:expr, |$b:ident| $builder:expr, $color:expr;)*) => {
13004            $(
13005                #[doc = concat!("input_decorator_test.dart '", $dart, "'.")]
13006                #[test]
13007                fn $name() {
13008                    test_widgets(|tester| {
13009                        let $d = hint_style_decoration($outlined, $with_label);
13010                        let $b = BuildInputDecorator::new($decoration);
13011                        check_hint_style(tester, $builder, $color);
13012                    });
13013                }
13014            )*
13015        };
13016    }
13017
13018        hint_style_cases! {
13019            filled_enabled_hint_is_body_large_in_on_surface_variant:
13020                "hint - for filled text field without label - when field is enabled - hint has correct style when visible",
13021                false, false, |d| d, |b| b.is_empty(true), on_surface_variant;
13022            filled_disabled_hint_is_body_large_in_on_surface_at_38_percent:
13023                "hint - for filled text field without label - when field is disabled - hint has correct style when visible",
13024                false, false, |d| d.enabled(false), |b| b.is_empty(true), disabled_on_surface;
13025            filled_hovered_hint_is_body_large_in_on_surface_variant:
13026                "hint - for filled text field without label - when field is hovered - hint has correct style when visible",
13027                false, false, |d| d, |b| b.is_hovering(true).is_empty(true), on_surface_variant;
13028            filled_focused_hint_is_body_large_in_on_surface_variant:
13029                "hint - for filled text field without label - when field is focused - hint has correct style when visible",
13030                false, false, |d| d, |b| b.is_focused(true).is_empty(true), on_surface_variant;
13031            filled_error_hint_is_body_large_in_on_surface_variant:
13032                "hint - for filled text field without label - when field is in error - hint has correct style when visible",
13033                false, false, |d| d.error_text(ERROR_TEXT), |b| b.is_empty(true), on_surface_variant;
13034            filled_labelled_focused_hint_is_body_large_in_on_surface_variant:
13035                "hint - for filled text field with label - when field is focused - hint has correct style when visible",
13036                false, true, |d| d, |b| b.is_focused(true).is_empty(true), on_surface_variant;
13037            outlined_enabled_hint_is_body_large_in_on_surface_variant:
13038                "hint - for outlined text field without label - when field is enabled - hint has correct style when visible",
13039                true, false, |d| d, |b| b.is_empty(true), on_surface_variant;
13040            outlined_disabled_hint_is_body_large_in_on_surface_at_38_percent:
13041                "hint - for outlined text field without label - when field is disabled - hint has correct style when visible",
13042                true, false, |d| d.enabled(false), |b| b.is_empty(true), disabled_on_surface;
13043            outlined_hovered_hint_is_body_large_in_on_surface_variant:
13044                "hint - for outlined text field without label - when field is hovered - hint has correct style when visible",
13045                true, false, |d| d, |b| b.is_hovering(true).is_empty(true), on_surface_variant;
13046            outlined_focused_hint_is_body_large_in_on_surface_variant:
13047                "hint - for outlined text field without label - when field is focused - hint has correct style when visible",
13048                true, false, |d| d, |b| b.is_focused(true).is_empty(true), on_surface_variant;
13049            outlined_error_hint_is_body_large_in_on_surface_variant:
13050                "hint - for outlined text field without label - when field is in error - hint has correct style when visible",
13051                true, false, |d| d.error_text(ERROR_TEXT), |b| b.is_empty(true), on_surface_variant;
13052            outlined_labelled_focused_hint_is_body_large_in_on_surface_variant:
13053                "hint - for outlined text field with label - when field is focused - hint has correct style when visible",
13054                true, true, |d| d, |b| b.is_focused(true).is_empty(true), on_surface_variant;
13055        }
13056
13057        // ----- InputDecoration.alignLabelWithHint -----
13058
13059        // input_decorator_test.dart 'InputDecoration.alignLabelWithHint - positions
13060        // InputDecoration.labelText vertically aligned with the hint' and 'positions
13061        // InputDecoration.label vertically aligned with the hint'.
13062        #[test]
13063        fn align_label_with_hint_centres_the_label_on_the_hint() {
13064            test_widgets(|tester| {
13065                pump(
13066                    tester,
13067                    BuildInputDecorator::new(
13068                        InputDecoration::new()
13069                            .label_text(LABEL_TEXT)
13070                            .align_label_with_hint(true)
13071                            .hint_text(HINT_TEXT),
13072                    )
13073                    .is_empty(true),
13074                );
13075                // Label and hint should be vertically aligned.
13076                assert_eq!(
13077                    get_label_rect(tester).center().dy(),
13078                    get_hint_rect(tester).center().dy()
13079                );
13080            });
13081        }
13082
13083        fn ac_unit() -> WidgetRef {
13084            Icon::new(Some(Icons::ac_unit())).into_widget()
13085        }
13086
13087        // input_decorator_test.dart 'InputDecoration.alignLabelWithHint - Horizontal alignment -
13088        // Label for outlined decoration aligns horizontally with prefixIcon by default'.
13089        #[test]
13090        fn an_outlined_label_aligns_with_the_prefix_icon_by_default() {
13091            test_widgets(|tester| {
13092                pump(
13093                    tester,
13094                    BuildInputDecorator::new(
13095                        InputDecoration::new()
13096                            .prefix_icon(ac_unit())
13097                            .label_text(LABEL_TEXT)
13098                            .border(OutlineInputBorder::new()),
13099                    )
13100                    .is_focused(true),
13101                );
13102                // Label left padding is 16.0 (12.0 right padding for a decoration with icons + 4.0
13103                // extra padding for the floating label)
13104                assert_eq!(get_label_rect(tester).left, 16.0);
13105                // Based on M3 spec, the expected horizontal position is 52 (12 padding, 24 icon, 16
13106                // gap between icon and input).
13107                assert_eq!(get_input_rect(tester).left, 52.0);
13108            });
13109        }
13110
13111        // input_decorator_test.dart 'InputDecoration.alignLabelWithHint - Horizontal alignment -
13112        // Label for outlined decoration aligns horizontally with input when alignLabelWithHint is
13113        // true'.
13114        #[test]
13115        fn an_outlined_label_aligned_with_the_hint_aligns_with_the_input() {
13116            test_widgets(|tester| {
13117                pump(
13118                    tester,
13119                    BuildInputDecorator::new(
13120                        InputDecoration::new()
13121                            .prefix_icon(ac_unit())
13122                            .label_text(LABEL_TEXT)
13123                            .border(OutlineInputBorder::new())
13124                            .align_label_with_hint(true),
13125                    )
13126                    .is_focused(true),
13127                );
13128                assert_eq!(get_label_rect(tester).left, get_input_rect(tester).left);
13129            });
13130        }
13131
13132        // input_decorator_test.dart 'InputDecoration.alignLabelWithHint - Horizontal alignment -
13133        // Label for filled decoration is horizontally aligned with text by default'.
13134        #[test]
13135        fn a_filled_label_aligns_with_the_input_by_default() {
13136            test_widgets(|tester| {
13137                pump(
13138                    tester,
13139                    BuildInputDecorator::new(
13140                        InputDecoration::new()
13141                            .prefix_icon(ac_unit())
13142                            .label_text(LABEL_TEXT)
13143                            .filled(true),
13144                    )
13145                    .is_focused(true),
13146                );
13147                // Label and input are horizontally aligned despite `alignLabelWithHint` being
13148                // false (default value).
13149                assert_eq!(get_label_rect(tester).left, get_input_rect(tester).left);
13150            });
13151        }
13152
13153        // ----- hint opacity animation -----
13154
13155        fn assert_in_exclusive_range(value: f64, low: f64, high: f64) {
13156            assert!(
13157                low < value && value < high,
13158                "{value} not in ({low}, {high})"
13159            );
13160        }
13161
13162        /// The three 'hint opacity animation' cases: the hint fades in when the empty decorator
13163        /// gains the focus and out when it loses it, in steps of `step` for `steps` steps.
13164        fn check_hint_fade(
13165            tester: &mut WidgetTester,
13166            decoration: InputDecoration,
13167            theme: Option<InputDecorationThemeData>,
13168            step: u64,
13169            settle: Option<u64>,
13170        ) {
13171            let build = |is_focused: bool| {
13172                let mut builder = BuildInputDecorator::new(decoration.clone())
13173                    .is_empty(true)
13174                    .is_focused(is_focused);
13175                if let Some(theme) = &theme {
13176                    builder = builder.input_decoration_theme(theme.clone());
13177                }
13178                builder.build()
13179            };
13180            // Build once without focus.
13181            tester.pump_widget(build(false));
13182            // Hint is not visible (opacity 0.0).
13183            assert_eq!(get_hint_opacity(tester), 0.0);
13184
13185            // Focus the decorator to trigger the animation.
13186            tester.pump_widget(build(true));
13187            tester.pump_by(ms(step));
13188            let first = get_hint_opacity(tester);
13189            assert_in_exclusive_range(first, 0.0, 1.0);
13190            tester.pump_by(ms(step));
13191            let second = get_hint_opacity(tester);
13192            assert_in_exclusive_range(second, first, 1.0);
13193            tester.pump_by(settle.map_or(K_TRANSITION_DURATION, ms));
13194            // Hint is fully visible (opacity 1.0).
13195            assert_eq!(get_hint_opacity(tester), 1.0);
13196
13197            // Unfocus the decorator to trigger the reversed animation.
13198            tester.pump_widget(build(false));
13199            tester.pump_by(ms(step));
13200            let first = get_hint_opacity(tester);
13201            assert_in_exclusive_range(first, 0.0, 1.0);
13202            tester.pump_by(ms(step));
13203            let second = get_hint_opacity(tester);
13204            assert_in_exclusive_range(second, 0.0, first);
13205            if let Some(settle) = settle {
13206                tester.pump_by(ms(settle));
13207                assert_eq!(get_hint_opacity(tester), 0.0);
13208            }
13209        }
13210
13211        // input_decorator_test.dart 'hint opacity animation - default duration'.
13212        #[test]
13213        fn the_hint_fades_in_and_out_in_20_ms_by_default() {
13214            test_widgets(|tester| {
13215                // The animation's default duration is 20ms.
13216                check_hint_fade(
13217                    tester,
13218                    InputDecoration::new()
13219                        .label_text(LABEL_TEXT)
13220                        .hint_text(HINT_TEXT),
13221                    None,
13222                    9,
13223                    None,
13224                );
13225            });
13226        }
13227
13228        // input_decorator_test.dart 'hint opacity animation - custom duration'.
13229        #[test]
13230        fn the_hint_fades_for_the_decoration_hint_fade_duration() {
13231            test_widgets(|tester| {
13232                // The animation's duration is set to 120ms.
13233                check_hint_fade(
13234                    tester,
13235                    InputDecoration::new()
13236                        .label_text(LABEL_TEXT)
13237                        .hint_text(HINT_TEXT)
13238                        .hint_fade_duration(ms(120)),
13239                    None,
13240                    50,
13241                    Some(50),
13242                );
13243            });
13244        }
13245
13246        // input_decorator_test.dart 'hint opacity animation - duration from theme'.
13247        #[test]
13248        fn the_hint_fades_for_the_theme_hint_fade_duration() {
13249            test_widgets(|tester| {
13250                // The animation's duration is set to 120ms.
13251                check_hint_fade(
13252                    tester,
13253                    InputDecoration::new()
13254                        .label_text(LABEL_TEXT)
13255                        .hint_text(HINT_TEXT),
13256                    Some(InputDecorationThemeData::new().hint_fade_duration(ms(120))),
13257                    50,
13258                    Some(50),
13259                );
13260            });
13261        }
13262
13263        // input_decorator_test.dart 'Material3 - InputDecoration hint - InputDecorator shows hint
13264        // widget'.
13265        #[test]
13266        fn the_decorator_shows_a_hint_widget() {
13267            test_widgets(|tester| {
13268                pump(
13269                    tester,
13270                    BuildInputDecorator::new(InputDecoration::new().hint(Text::new("hint"))),
13271                );
13272                expect(tester, &find::text("hint"), finds_one_widget());
13273            });
13274        }
13275
13276        // input_decorator_test.dart 'Material3 - InputDecoration hint - hint style overflow works'.
13277        #[test]
13278        fn the_hint_style_overflow_reaches_the_hint_text() {
13279            test_widgets(|tester| {
13280                let hint_text = "hint text".repeat(20);
13281                let hint_style = TextStyle::new()
13282                    .font_size(14.0)
13283                    .overflow(TextOverflow::Fade);
13284                let decoration = InputDecoration::new()
13285                    .hint_text(hint_text.clone())
13286                    .hint_style(hint_style);
13287                pump(tester, BuildInputDecorator::new(decoration.clone()));
13288                tester.pump_by(K_TRANSITION_DURATION);
13289
13290                let hint = tester.element(find::text(&hint_text));
13291                let overflow = tester.widget(hint, |text: &Text| {
13292                    text.style.as_ref().and_then(|style| style.overflow)
13293                });
13294                assert_eq!(
13295                    overflow,
13296                    decoration
13297                        .hint_style
13298                        .as_ref()
13299                        .and_then(|style| style.overflow)
13300                );
13301            });
13302        }
13303
13304        // input_decorator_test.dart 'Material3 - InputDecoration hint - Widget height collapses
13305        // from hint height when maintainHintSize is false'.
13306        #[test]
13307        fn the_height_collapses_from_the_hint_height_without_maintain_hint_size() {
13308            test_widgets(|tester| {
13309                let decoration = InputDecoration::new()
13310                    .hint_text("hint".repeat(20))
13311                    .hint_max_lines(3)
13312                    .maintain_hint_size(false);
13313                pump(tester, BuildInputDecorator::new(decoration));
13314                assert_eq!(get_decorator_rect(tester).height(), 48.0);
13315            });
13316        }
13317
13318        // input_decorator_test.dart 'Material3 - InputDecoration hint - Widget height stays at hint
13319        // height by default'.
13320        #[test]
13321        fn the_height_stays_at_the_hint_height_by_default() {
13322            test_widgets(|tester| {
13323                // Dart's hint is 'hint' * 20, which wraps onto two lines at 800: FlutterTest
13324                // breaks a word too long for its line, which Waft's text layout does not, so
13325                // the line break is explicit here.
13326                let hint_text = format!("{}\n{}", "hint".repeat(10), "hint".repeat(10));
13327                let decoration = InputDecoration::new()
13328                    .hint_max_lines(3)
13329                    .hint_text(hint_text.clone());
13330                pump(tester, BuildInputDecorator::new(decoration));
13331                let hint_height = tester.get_rect(find::text(&hint_text)).height();
13332                let input_height = get_decorator_rect(tester).height();
13333                assert_eq!(input_height, hint_height + 16.0);
13334            });
13335        }
13336
13337        /// Dart's `find.text(hintText)` count.
13338        fn hint_count(tester: &WidgetTester) -> usize {
13339            find::text(HINT_TEXT).evaluate(tester).len()
13340        }
13341
13342        fn fading_hint_decoration() -> InputDecoration {
13343            InputDecoration::new()
13344                .hint_text(HINT_TEXT)
13345                .hint_max_lines(3)
13346                .hint_fade_duration(ms(120))
13347                .maintain_hint_size(false)
13348        }
13349
13350        // input_decorator_test.dart 'Material3 - InputDecoration hint - hintFadeDuration applies to
13351        // hint fade-in when maintainHintSize is false'.
13352        #[test]
13353        fn the_hint_fade_duration_applies_to_the_fade_in_without_maintain_hint_size() {
13354            test_widgets(|tester| {
13355                // Build once with empty content.
13356                pump(tester, BuildInputDecorator::new(fading_hint_decoration()));
13357
13358                // Hint is not exist.
13359                assert_eq!(hint_count(tester), 0);
13360
13361                // Rebuild with empty content.
13362                tester.pump_widget(
13363                    BuildInputDecorator::new(fading_hint_decoration())
13364                        .is_empty(true)
13365                        .build(),
13366                );
13367
13368                // The hint's opacity animates from 0.0 to 1.0.
13369                tester.pump_by(ms(50));
13370                let hint_opacity_50ms = get_hint_opacity(tester);
13371                assert_in_exclusive_range(hint_opacity_50ms, 0.0, 1.0);
13372                tester.pump_by(ms(50));
13373                let hint_opacity_100ms = get_hint_opacity(tester);
13374                assert_in_exclusive_range(hint_opacity_100ms, hint_opacity_50ms, 1.0);
13375                tester.pump_by(ms(20));
13376                assert_eq!(get_hint_opacity(tester), 1.0);
13377            });
13378        }
13379
13380        // input_decorator_test.dart 'Material3 - InputDecoration hint - hintFadeDuration applies to
13381        // hint fade-out when maintainHintSize is false'.
13382        #[test]
13383        fn the_hint_fade_duration_applies_to_the_fade_out_without_maintain_hint_size() {
13384            test_widgets(|tester| {
13385                // Build once with empty content.
13386                pump(
13387                    tester,
13388                    BuildInputDecorator::new(fading_hint_decoration()).is_empty(true),
13389                );
13390
13391                // Hint is visible (opacity 1.0).
13392                assert_eq!(get_hint_opacity(tester), 1.0);
13393
13394                // Rebuild with non-empty content.
13395                tester.pump_widget(BuildInputDecorator::new(fading_hint_decoration()).build());
13396
13397                // The hint's opacity animates from 1.0 to 0.0.
13398                tester.pump_by(ms(50));
13399                let hint_opacity_50ms = get_hint_opacity(tester);
13400                assert_in_exclusive_range(hint_opacity_50ms, 0.0, 1.0);
13401                tester.pump_by(ms(50));
13402                let hint_opacity_100ms = get_hint_opacity(tester);
13403                assert_in_exclusive_range(hint_opacity_100ms, 0.0, hint_opacity_50ms);
13404                tester.pump_by(ms(20));
13405                assert_eq!(get_hint_opacity(tester), 0.0);
13406                tester.pump_by(ms(1));
13407                // The hintText replaced with SizeBox.
13408                assert_eq!(hint_count(tester), 0);
13409            });
13410        }
13411
13412        fn hint_edge(
13413            tester: &mut WidgetTester,
13414            maintain_hint_size: bool,
13415            text_direction: TextDirection,
13416        ) -> Rect {
13417            pump(
13418                tester,
13419                BuildInputDecorator::new(
13420                    InputDecoration::new()
13421                        .hint_text(HINT_TEXT)
13422                        .maintain_hint_size(maintain_hint_size),
13423                )
13424                .is_empty(true)
13425                .text_direction(text_direction),
13426            );
13427            get_hint_rect(tester)
13428        }
13429
13430        // input_decorator_test.dart 'Material3 - InputDecoration hint - Hint does not change
13431        // position when maintainHintSize is false - LTR'.
13432        #[test]
13433        fn the_hint_keeps_its_position_without_maintain_hint_size_in_ltr() {
13434            test_widgets(|tester| {
13435                let expected_hint_left = hint_edge(tester, true, TextDirection::Ltr).left;
13436                assert_eq!(
13437                    hint_edge(tester, false, TextDirection::Ltr).left,
13438                    expected_hint_left
13439                );
13440            });
13441        }
13442
13443        // input_decorator_test.dart 'Material3 - InputDecoration hint - Hint does not change
13444        // position when maintainHintSize is false - RTL'.
13445        #[test]
13446        fn the_hint_keeps_its_position_without_maintain_hint_size_in_rtl() {
13447            test_widgets(|tester| {
13448                let expected_hint_right = hint_edge(tester, true, TextDirection::Rtl).right;
13449                assert_eq!(
13450                    hint_edge(tester, false, TextDirection::Rtl).right,
13451                    expected_hint_right
13452                );
13453            });
13454        }
13455    }
13456
13457    // input_decorator_test.dart's helper/counter/error,
13458    // constraints, prefix/suffix, collapsed, floatingLabelAlignment and isDense groups.
13459    mod supporting_and_affixes {
13460        #![allow(deprecated)]
13461        use waft_widgets::testing::{
13462            TargetPlatformVariant, WidgetTester, test_widgets, test_widgets_variant,
13463        };
13464
13465        use std::cell::Cell;
13466        use std::rc::Rc;
13467        use std::time::Duration;
13468
13469        use waft_embedder::{Color, Rect, Size};
13470        use waft_foundation::Listener;
13471        use waft_painting::{EdgeInsetsGeometry, TextDirection, TextStyle};
13472        use waft_rendering::BoxConstraints;
13473        use waft_widgets::{
13474            AnimatedOpacity, Center, FadeTransition, Focus, GestureDetector, Icon, IconData,
13475            IntoWidget, RichText, SizedBox, Text, WidgetRef, downcast_widget,
13476        };
13477
13478        use super::super::*;
13479        use super::common::K_TRANSITION_DURATION;
13480        use super::common::*;
13481        use crate::icons::Icons;
13482        use crate::input_border::OutlineInputBorder;
13483        use crate::theme::Theme;
13484        use crate::theme_data::ThemeData;
13485
13486        // Overall height for InputDecorator (filled or outlined) is 76dp on mobile:
13487        //    8 - top padding
13488        //   12 - floating label (font size = 16 * 0.75, line height is forced to 1.0)
13489        //    4 - gap between label and input
13490        //   24 - input text (font size = 16, line height = 1.5)
13491        //    8 - bottom padding
13492        //    4 - gap above helper/error/counter
13493        //   16 - helper/counter (font size = 12, line height is 1.5)
13494        const TOP_PADDING: f64 = 8.0;
13495        const FLOATING_LABEL_HEIGHT: f64 = 12.0;
13496        const LABEL_INPUT_GAP: f64 = 4.0;
13497        const INPUT_HEIGHT: f64 = 24.0;
13498        const BOTTOM_PADDING: f64 = 8.0;
13499        const HELPER_GAP: f64 = 4.0;
13500        const HELPER_HEIGHT: f64 = 16.0;
13501        const CONTAINER_HEIGHT: f64 =
13502            TOP_PADDING + FLOATING_LABEL_HEIGHT + LABEL_INPUT_GAP + INPUT_HEIGHT + BOTTOM_PADDING; // 56.0
13503        const FULL_HEIGHT: f64 = CONTAINER_HEIGHT + HELPER_GAP + HELPER_HEIGHT; // 76.0
13504        const ERROR_HEIGHT: f64 = HELPER_HEIGHT;
13505        const HINT_HEIGHT: f64 = INPUT_HEIGHT;
13506        const HELPER_START_PADDING: f64 = 16.0;
13507        const COUNTER_END_PADDING: f64 = 16.0;
13508
13509        /// A tester with the Material icon font, whose glyphs the icon cases measure.
13510        fn pump(tester: &mut WidgetTester, decorator: BuildInputDecorator) {
13511            tester.pump_widget(decorator.build());
13512        }
13513
13514        /// Dart's `Theme.of(tester.element(findDecorator()))`.
13515        fn decorator_theme(tester: &WidgetTester) -> Rc<ThemeData> {
13516            let element = tester.element(find::by_type::<InputDecorator>());
13517            let mut app = tester.cell.borrow_mut();
13518            Theme::of(&mut app, element)
13519        }
13520
13521        /// Dart's `tester.widget<RichText>(find.descendant(of: find.text(text), matching:
13522        /// find.byType(RichText))).text.style!`.
13523        fn text_style(tester: &WidgetTester, text: &str) -> TextStyle {
13524            let rich_text = tester.element(find::descendant(
13525                find::text(text),
13526                find::by_type::<RichText>(),
13527            ));
13528            tester.widget(rich_text, |rich_text: &RichText| {
13529                rich_text.text.style().cloned().expect("a styled text")
13530            })
13531        }
13532
13533        /// Dart's `tester.getRect(find.text(text))` over a `Text`.
13534        fn string_rect(tester: &WidgetTester, text: &str) -> Rect {
13535            tester.get_rect(find::text(text))
13536        }
13537
13538        fn body_small_with(theme: &ThemeData, color: Color) -> TextStyle {
13539            theme
13540                .text_theme
13541                .body_small
13542                .clone()
13543                .expect("bodySmall")
13544                .copy_with()
13545                .color(color)
13546        }
13547
13548        fn filled() -> InputDecoration {
13549            InputDecoration::new().filled(true)
13550        }
13551
13552        fn outlined() -> InputDecoration {
13553            InputDecoration::new().border(OutlineInputBorder::new())
13554        }
13555
13556        /// The decoration of the 'Helper and counter are correctly positioned' cases, with
13557        /// the label, helper and counter texts.
13558        fn measured_supporting(base: InputDecoration) -> InputDecoration {
13559            base.label_text(LABEL_TEXT)
13560                .helper_text(HELPER_TEXT)
13561                .counter_text(COUNTER_TEXT)
13562        }
13563
13564        /// The decoration of the 'Helper and counter are correctly styled' cases.
13565        fn styled_supporting(base: InputDecoration) -> InputDecoration {
13566            base.label_text(LABEL_TEXT)
13567                .helper_text(HELPER_TEXT)
13568                .counter_text(COUNTER_TEXT)
13569        }
13570
13571        fn check_helper_and_counter_positions(tester: &WidgetTester) {
13572            assert_eq!(get_decorator_rect(tester).height(), FULL_HEIGHT);
13573            assert_eq!(get_border_bottom(tester), CONTAINER_HEIGHT);
13574            let helper = tester.get_rect(find::text(HELPER_TEXT));
13575            assert_eq!(helper.top, CONTAINER_HEIGHT + HELPER_GAP);
13576            assert_eq!(helper.height(), HELPER_HEIGHT);
13577            assert_eq!(helper.left, HELPER_START_PADDING);
13578            let counter = tester.get_rect(find::text(COUNTER_TEXT));
13579            assert_eq!(counter.top, CONTAINER_HEIGHT + HELPER_GAP);
13580            assert_eq!(counter.height(), HELPER_HEIGHT);
13581            // The global transform is f32, which leaves the counter's right a rounding off 784.
13582            assert_f32_equals(counter.right, 800.0 - COUNTER_END_PADDING);
13583        }
13584
13585        fn check_error_and_counter_positions(tester: &WidgetTester) {
13586            assert_eq!(get_decorator_rect(tester).height(), FULL_HEIGHT);
13587            assert_eq!(get_border_bottom(tester), CONTAINER_HEIGHT);
13588            let error = tester.get_rect(find::text(ERROR_TEXT));
13589            assert_eq!(error.top, CONTAINER_HEIGHT + HELPER_GAP);
13590            assert_eq!(error.height(), ERROR_HEIGHT);
13591            assert_eq!(error.left, HELPER_START_PADDING);
13592            let counter = tester.get_rect(find::text(COUNTER_TEXT));
13593            assert_eq!(counter.top, CONTAINER_HEIGHT + HELPER_GAP);
13594            assert_eq!(counter.height(), ERROR_HEIGHT);
13595            // The global transform is f32, which leaves the counter's right a rounding off 784.
13596            assert_f32_equals(counter.right, 800.0 - COUNTER_END_PADDING);
13597        }
13598
13599        fn check_helper_and_counter_style(
13600            tester: &WidgetTester,
13601            color: impl Fn(&ThemeData) -> Color,
13602        ) {
13603            let theme = decorator_theme(tester);
13604            let expected_style = body_small_with(&theme, color(&theme));
13605            assert_eq!(text_style(tester, HELPER_TEXT), expected_style);
13606            assert_eq!(text_style(tester, COUNTER_TEXT), expected_style);
13607        }
13608
13609        fn check_error_and_counter_style(tester: &WidgetTester) {
13610            let theme = decorator_theme(tester);
13611            assert_eq!(
13612                text_style(tester, ERROR_TEXT),
13613                body_small_with(&theme, theme.color_scheme.error())
13614            );
13615            assert_eq!(
13616                text_style(tester, COUNTER_TEXT),
13617                body_small_with(&theme, theme.color_scheme.on_surface_variant())
13618            );
13619        }
13620
13621        fn on_surface_variant(theme: &ThemeData) -> Color {
13622            theme.color_scheme.on_surface_variant()
13623        }
13624
13625        fn disabled_on_surface(theme: &ThemeData) -> Color {
13626            theme.color_scheme.on_surface().with_opacity(0.38)
13627        }
13628
13629        // input_decorator_test.dart 'Material3 - InputDecoration helper/counter/error - for filled
13630        // text field - when field is enabled - Helper and counter are correctly positioned'.
13631        #[test]
13632        fn filled_enabled_helper_and_counter_are_correctly_positioned() {
13633            test_widgets(|tester| {
13634                pump(
13635                    tester,
13636                    BuildInputDecorator::new(measured_supporting(filled())),
13637                );
13638                check_helper_and_counter_positions(tester);
13639            });
13640        }
13641
13642        // input_decorator_test.dart '... for filled text field - when field is enabled - Helper
13643        // and counter are correctly styled'.
13644        #[test]
13645        fn filled_enabled_helper_and_counter_are_correctly_styled() {
13646            test_widgets(|tester| {
13647                pump(
13648                    tester,
13649                    BuildInputDecorator::new(styled_supporting(filled())),
13650                );
13651                check_helper_and_counter_style(tester, on_surface_variant);
13652            });
13653        }
13654
13655        // input_decorator_test.dart '... for filled text field - when field is disabled - Helper
13656        // and counter are correctly positioned'.
13657        #[test]
13658        fn filled_disabled_helper_and_counter_are_correctly_positioned() {
13659            test_widgets(|tester| {
13660                pump(
13661                    tester,
13662                    BuildInputDecorator::new(measured_supporting(filled().enabled(false))),
13663                );
13664                check_helper_and_counter_positions(tester);
13665            });
13666        }
13667
13668        // input_decorator_test.dart '... for filled text field - when field is disabled - Helper
13669        // and counter are correctly styled'.
13670        #[test]
13671        fn filled_disabled_helper_and_counter_are_correctly_styled() {
13672            test_widgets(|tester| {
13673                pump(
13674                    tester,
13675                    BuildInputDecorator::new(styled_supporting(filled().enabled(false))),
13676                );
13677                check_helper_and_counter_style(tester, disabled_on_surface);
13678            });
13679        }
13680
13681        // input_decorator_test.dart '... for filled text field - when field is hovered - Helper
13682        // and counter are correctly positioned'.
13683        #[test]
13684        fn filled_hovered_helper_and_counter_are_correctly_positioned() {
13685            test_widgets(|tester| {
13686                pump(
13687                    tester,
13688                    BuildInputDecorator::new(measured_supporting(filled())).is_hovering(true),
13689                );
13690                check_helper_and_counter_positions(tester);
13691            });
13692        }
13693
13694        // input_decorator_test.dart '... for filled text field - when field is hovered - Helper
13695        // and counter are correctly styled'.
13696        #[test]
13697        fn filled_hovered_helper_and_counter_are_correctly_styled() {
13698            test_widgets(|tester| {
13699                pump(
13700                    tester,
13701                    BuildInputDecorator::new(styled_supporting(filled())).is_hovering(true),
13702                );
13703                check_helper_and_counter_style(tester, on_surface_variant);
13704            });
13705        }
13706
13707        // input_decorator_test.dart '... for filled text field - when field is focused - Helper
13708        // and counter are correctly positioned'.
13709        #[test]
13710        fn filled_focused_helper_and_counter_are_correctly_positioned() {
13711            test_widgets(|tester| {
13712                pump(
13713                    tester,
13714                    BuildInputDecorator::new(measured_supporting(filled())).is_focused(true),
13715                );
13716                check_helper_and_counter_positions(tester);
13717            });
13718        }
13719
13720        // input_decorator_test.dart '... for filled text field - when field is focused - Helper
13721        // and counter are correctly styled'.
13722        #[test]
13723        fn filled_focused_helper_and_counter_are_correctly_styled() {
13724            test_widgets(|tester| {
13725                pump(
13726                    tester,
13727                    BuildInputDecorator::new(styled_supporting(filled())).is_focused(true),
13728                );
13729                check_helper_and_counter_style(tester, on_surface_variant);
13730            });
13731        }
13732
13733        fn check_error_shows_and_helper_hides(tester: &mut WidgetTester, base: InputDecoration) {
13734            pump(
13735                tester,
13736                BuildInputDecorator::new(styled_supporting(base).error_text(ERROR_TEXT))
13737                    .is_focused(true),
13738            );
13739            expect(tester, &find::text(ERROR_TEXT), finds_one_widget());
13740            expect(tester, &find::text(COUNTER_TEXT), finds_one_widget());
13741            expect(tester, &find::text(HELPER_TEXT), finds_nothing());
13742        }
13743
13744        fn check_error_positions(tester: &mut WidgetTester, base: InputDecoration) {
13745            pump(
13746                tester,
13747                BuildInputDecorator::new(measured_supporting(base).error_text(ERROR_TEXT))
13748                    .is_focused(true),
13749            );
13750            check_error_and_counter_positions(tester);
13751        }
13752
13753        fn check_error_style(tester: &mut WidgetTester, base: InputDecoration) {
13754            pump(
13755                tester,
13756                BuildInputDecorator::new(styled_supporting(base).error_text(ERROR_TEXT))
13757                    .is_focused(true),
13758            );
13759            check_error_and_counter_style(tester);
13760        }
13761
13762        // input_decorator_test.dart '... for filled text field - when field is in error - Error and
13763        // counter are visible, helper is not visible'.
13764        #[test]
13765        fn filled_error_and_counter_are_visible_and_the_helper_is_not() {
13766            test_widgets(|tester| check_error_shows_and_helper_hides(tester, filled()));
13767        }
13768
13769        // input_decorator_test.dart '... for filled text field - when field is in error - Error and
13770        // counter are correctly positioned'.
13771        #[test]
13772        fn filled_error_and_counter_are_correctly_positioned() {
13773            test_widgets(|tester| check_error_positions(tester, filled()));
13774        }
13775
13776        // input_decorator_test.dart '... for filled text field - when field is in error - Error and
13777        // counter are correctly styled'.
13778        #[test]
13779        fn filled_error_and_counter_are_correctly_styled() {
13780            test_widgets(|tester| check_error_style(tester, filled()));
13781        }
13782
13783        // input_decorator_test.dart '... for outlined text field - when field is enabled - Helper
13784        // and counter are correctly positioned'.
13785        #[test]
13786        fn outlined_enabled_helper_and_counter_are_correctly_positioned() {
13787            test_widgets(|tester| {
13788                pump(
13789                    tester,
13790                    BuildInputDecorator::new(measured_supporting(outlined())),
13791                );
13792                check_helper_and_counter_positions(tester);
13793            });
13794        }
13795
13796        // input_decorator_test.dart '... for outlined text field - when field is enabled - Helper
13797        // and counter are correctly styled'.
13798        #[test]
13799        fn outlined_enabled_helper_and_counter_are_correctly_styled() {
13800            test_widgets(|tester| {
13801                pump(
13802                    tester,
13803                    BuildInputDecorator::new(styled_supporting(outlined())),
13804                );
13805                check_helper_and_counter_style(tester, on_surface_variant);
13806            });
13807        }
13808
13809        // input_decorator_test.dart '... for outlined text field - when field is disabled - Helper
13810        // and counter are correctly positioned'.
13811        #[test]
13812        fn outlined_disabled_helper_and_counter_are_correctly_positioned() {
13813            test_widgets(|tester| {
13814                pump(
13815                    tester,
13816                    BuildInputDecorator::new(measured_supporting(outlined().enabled(false))),
13817                );
13818                check_helper_and_counter_positions(tester);
13819            });
13820        }
13821
13822        // input_decorator_test.dart '... for outlined text field - when field is disabled - Helper
13823        // and counter are correctly styled'.
13824        #[test]
13825        fn outlined_disabled_helper_and_counter_are_correctly_styled() {
13826            test_widgets(|tester| {
13827                pump(
13828                    tester,
13829                    BuildInputDecorator::new(styled_supporting(outlined().enabled(false))),
13830                );
13831                check_helper_and_counter_style(tester, disabled_on_surface);
13832            });
13833        }
13834
13835        // input_decorator_test.dart '... for outlined text field - when field is hovered - Helper
13836        // and counter are correctly positioned'.
13837        #[test]
13838        fn outlined_hovered_helper_and_counter_are_correctly_positioned() {
13839            test_widgets(|tester| {
13840                pump(
13841                    tester,
13842                    BuildInputDecorator::new(measured_supporting(outlined())).is_hovering(true),
13843                );
13844                check_helper_and_counter_positions(tester);
13845            });
13846        }
13847
13848        // input_decorator_test.dart '... for outlined text field - when field is hovered - Helper
13849        // and counter are correctly styled'.
13850        #[test]
13851        fn outlined_hovered_helper_and_counter_are_correctly_styled() {
13852            test_widgets(|tester| {
13853                pump(
13854                    tester,
13855                    BuildInputDecorator::new(styled_supporting(outlined())).is_hovering(true),
13856                );
13857                check_helper_and_counter_style(tester, on_surface_variant);
13858            });
13859        }
13860
13861        // input_decorator_test.dart '... for outlined text field - when field is focused - Helper
13862        // and counter are correctly positioned'.
13863        #[test]
13864        fn outlined_focused_helper_and_counter_are_correctly_positioned() {
13865            test_widgets(|tester| {
13866                pump(
13867                    tester,
13868                    BuildInputDecorator::new(measured_supporting(outlined())).is_focused(true),
13869                );
13870                check_helper_and_counter_positions(tester);
13871            });
13872        }
13873
13874        // input_decorator_test.dart '... for outlined text field - when field is focused - Helper
13875        // and counter are correctly styled'.
13876        #[test]
13877        fn outlined_focused_helper_and_counter_are_correctly_styled() {
13878            test_widgets(|tester| {
13879                pump(
13880                    tester,
13881                    BuildInputDecorator::new(styled_supporting(outlined())).is_focused(true),
13882                );
13883                check_helper_and_counter_style(tester, on_surface_variant);
13884            });
13885        }
13886
13887        // input_decorator_test.dart '... for outlined text field - when field is in error - Error
13888        // and counter are visible, helper is not visible'.
13889        #[test]
13890        fn outlined_error_and_counter_are_visible_and_the_helper_is_not() {
13891            test_widgets(|tester| check_error_shows_and_helper_hides(tester, outlined()));
13892        }
13893
13894        // input_decorator_test.dart '... for outlined text field - when field is in error - Error
13895        // and counter are correctly positioned'.
13896        #[test]
13897        fn outlined_error_and_counter_are_correctly_positioned() {
13898            test_widgets(|tester| check_error_positions(tester, outlined()));
13899        }
13900
13901        // input_decorator_test.dart '... for outlined text field - when field is in error - Error
13902        // and counter are correctly styled'.
13903        #[test]
13904        fn outlined_error_and_counter_are_correctly_styled() {
13905            test_widgets(|tester| check_error_style(tester, outlined()));
13906        }
13907
13908        /// The error or helper `text`, `lines` lines high, and the decorator below it.
13909        fn check_supporting_lines(
13910            tester: &mut WidgetTester,
13911            decoration: InputDecoration,
13912            text: &str,
13913            lines: f64,
13914        ) {
13915            pump(tester, BuildInputDecorator::new(decoration));
13916            assert_more_or_less_equals_within(
13917                string_rect(tester, text).height(),
13918                ERROR_HEIGHT * lines,
13919                0.25,
13920            );
13921            assert_more_or_less_equals_within(
13922                get_decorator_rect(tester).height(),
13923                CONTAINER_HEIGHT + HELPER_GAP + ERROR_HEIGHT * lines,
13924                0.25,
13925            );
13926        }
13927
13928        // input_decorator_test.dart 'Multiline error/helper - Error height grows to accommodate
13929        // error text'.
13930        #[test]
13931        fn the_error_grows_to_accommodate_its_text() {
13932            test_widgets(|tester| {
13933                check_supporting_lines(
13934                    tester,
13935                    filled()
13936                        .label_text("label")
13937                        .error_text(THREE_LINES)
13938                        .error_max_lines(3),
13939                    THREE_LINES,
13940                    3.0,
13941                );
13942            });
13943        }
13944
13945        // input_decorator_test.dart 'Multiline error/helper - Error height is correct when
13946        // errorMaxLines is restricted'.
13947        #[test]
13948        fn the_error_height_is_correct_when_error_max_lines_is_restricted() {
13949            test_widgets(|tester| {
13950                check_supporting_lines(
13951                    tester,
13952                    filled()
13953                        .label_text("label")
13954                        .error_text(THREE_LINES)
13955                        .error_max_lines(2),
13956                    THREE_LINES,
13957                    2.0,
13958                );
13959            });
13960        }
13961
13962        // input_decorator_test.dart 'Multiline error/helper - Error height is correct when
13963        // errorMaxLines is bigger than the number of lines in errorText'.
13964        #[test]
13965        fn the_error_height_is_its_line_count_when_error_max_lines_is_bigger() {
13966            test_widgets(|tester| {
13967                check_supporting_lines(
13968                    tester,
13969                    filled()
13970                        .label_text("label")
13971                        .error_text(TWO_LINES)
13972                        .error_max_lines(3),
13973                    TWO_LINES,
13974                    2.0,
13975                );
13976            });
13977        }
13978
13979        // input_decorator_test.dart 'Multiline error/helper - Error height is not limited by
13980        // default'.
13981        #[test]
13982        fn the_error_height_is_not_limited_by_default() {
13983            test_widgets(|tester| {
13984                check_supporting_lines(
13985                    tester,
13986                    filled().label_text("label").error_text(THREE_LINES),
13987                    THREE_LINES,
13988                    3.0,
13989                );
13990            });
13991        }
13992
13993        // input_decorator_test.dart 'Multiline error/helper - InputDecorationThemeData.hintMaxLines
13994        // behaves as default value'.
13995        #[test]
13996        fn the_theme_hint_max_lines_is_the_default() {
13997            test_widgets(|tester| {
13998                pump(
13999                    tester,
14000                    BuildInputDecorator::new(InputDecoration::new().hint_text(THREE_LINES))
14001                        .input_decoration_theme(InputDecorationThemeData::new().hint_max_lines(2)),
14002                );
14003                assert_more_or_less_equals_within(
14004                    string_rect(tester, THREE_LINES).height(),
14005                    HINT_HEIGHT * 2.0,
14006                    0.25,
14007                );
14008                assert_more_or_less_equals_within(
14009                    get_decorator_rect(tester).height(),
14010                    TOP_PADDING + HINT_HEIGHT * 2.0 + BOTTOM_PADDING,
14011                    0.25,
14012                );
14013            });
14014        }
14015
14016        // input_decorator_test.dart 'Multiline error/helper - InputDecoration hintMaxLines default
14017        // expands with hintText'.
14018        #[test]
14019        fn the_hint_expands_with_its_text_by_default() {
14020            test_widgets(|tester| {
14021                pump(
14022                    tester,
14023                    BuildInputDecorator::new(InputDecoration::new().hint_text(THREE_LINES))
14024                        .input_decoration_theme(InputDecorationThemeData::new()),
14025                );
14026                assert_eq!(
14027                    get_decorator_rect(tester).height(),
14028                    TOP_PADDING + HINT_HEIGHT * 3.0 + BOTTOM_PADDING
14029                );
14030            });
14031        }
14032
14033        // input_decorator_test.dart 'Multiline error/helper - Helper height grows to accommodate
14034        // helper text'.
14035        #[test]
14036        fn the_helper_grows_to_accommodate_its_text() {
14037            test_widgets(|tester| {
14038                check_supporting_lines(
14039                    tester,
14040                    filled()
14041                        .label_text("label")
14042                        .helper_text(THREE_LINES)
14043                        .helper_max_lines(3),
14044                    THREE_LINES,
14045                    3.0,
14046                );
14047            });
14048        }
14049
14050        // input_decorator_test.dart 'Multiline error/helper - Helper height is correct when
14051        // maxLines is restricted'.
14052        #[test]
14053        fn the_helper_height_is_correct_when_helper_max_lines_is_restricted() {
14054            test_widgets(|tester| {
14055                check_supporting_lines(
14056                    tester,
14057                    filled()
14058                        .label_text("label")
14059                        .helper_text(THREE_LINES)
14060                        .helper_max_lines(2),
14061                    THREE_LINES,
14062                    2.0,
14063                );
14064            });
14065        }
14066
14067        // input_decorator_test.dart 'Multiline error/helper - Helper height is correct when
14068        // helperMaxLines is bigger than the number of lines in helperText'.
14069        #[test]
14070        fn the_helper_height_is_its_line_count_when_helper_max_lines_is_bigger() {
14071            test_widgets(|tester| {
14072                check_supporting_lines(
14073                    tester,
14074                    filled()
14075                        .label_text("label")
14076                        .helper_text(TWO_LINES)
14077                        .helper_max_lines(3),
14078                    TWO_LINES,
14079                    2.0,
14080                );
14081            });
14082        }
14083
14084        // input_decorator_test.dart 'Multiline error/helper - Helper height is not limited by
14085        // default'.
14086        #[test]
14087        fn the_helper_height_is_not_limited_by_default() {
14088            test_widgets(|tester| {
14089                check_supporting_lines(
14090                    tester,
14091                    filled().label_text("label").helper_text(THREE_LINES),
14092                    THREE_LINES,
14093                    3.0,
14094                );
14095            });
14096        }
14097
14098        // input_decorator_test.dart 'Helper widget - InputDecorator shows helper widget'.
14099        #[test]
14100        fn the_decorator_shows_a_helper_widget() {
14101            test_widgets(|tester| {
14102                pump(
14103                    tester,
14104                    BuildInputDecorator::new(
14105                        InputDecoration::new()
14106                            .helper(Text::new("helper").style(TextStyle::new().font_size(20.0))),
14107                    ),
14108                );
14109                expect(tester, &find::text("helper"), finds_one_widget());
14110            });
14111        }
14112
14113        // input_decorator_test.dart 'Helper widget - InputDecorator throws when helper text and
14114        // helper widget are provided'.
14115        #[test]
14116        #[should_panic(expected = "Declaring both helper and helperText is not supported.")]
14117        fn a_helper_text_and_a_helper_widget_together_panic() {
14118            test_widgets(|tester| {
14119                pump(
14120                    tester,
14121                    BuildInputDecorator::new(
14122                        InputDecoration::new()
14123                            .helper_text("helperText")
14124                            .helper(Text::new("helper").style(TextStyle::new().font_size(20.0))),
14125                    ),
14126                );
14127            });
14128        }
14129
14130        // input_decorator_test.dart 'Error widget - InputDecorator shows error widget'.
14131        #[test]
14132        fn the_decorator_shows_an_error_widget() {
14133            test_widgets(|tester| {
14134                pump(
14135                    tester,
14136                    BuildInputDecorator::new(
14137                        InputDecoration::new()
14138                            .error(Text::new("error").style(TextStyle::new().font_size(20.0))),
14139                    ),
14140                );
14141                expect(tester, &find::text("error"), finds_one_widget());
14142            });
14143        }
14144
14145        // input_decorator_test.dart 'Error widget - InputDecorator throws when error text and error
14146        // widget are provided'.
14147        #[test]
14148        #[should_panic(expected = "Declaring both error and errorText is not supported.")]
14149        fn an_error_text_and_an_error_widget_together_panic() {
14150            test_widgets(|tester| {
14151                pump(
14152                    tester,
14153                    BuildInputDecorator::new(
14154                        InputDecoration::new()
14155                            .error_text("errorText")
14156                            .error(Text::new("error").style(TextStyle::new().font_size(20.0))),
14157                    ),
14158                );
14159            });
14160        }
14161
14162        // input_decorator_test.dart 'Error widget - InputDecorator error widget text style defaults
14163        // to errorStyle'.
14164        #[test]
14165        fn an_error_widget_text_style_defaults_to_the_error_style() {
14166            test_widgets(|tester| {
14167                pump(
14168                    tester,
14169                    BuildInputDecorator::new(InputDecoration::new().error(Text::new(ERROR_TEXT))),
14170                );
14171                expect(tester, &find::text(ERROR_TEXT), finds_one_widget());
14172                let theme = decorator_theme(tester);
14173                assert_eq!(
14174                    text_style(tester, ERROR_TEXT),
14175                    body_small_with(&theme, theme.color_scheme.error())
14176                );
14177            });
14178        }
14179
14180        // input_decorator_test.dart 'Material3 - InputDecoration helper/counter/error -
14181        // InputDecorator with counter does not crash when given a 0 size'.
14182        #[test]
14183        fn a_decorator_with_a_counter_does_not_crash_at_zero_size() {
14184            test_widgets(|tester| {
14185                let decorator = BuildInputDecorator::new(
14186                    InputDecoration::new()
14187                        .content_padding(EdgeInsetsGeometry::directional(99.0, 99.0, 99.0, 99.0))
14188                        .prefix_icon(Focus::new(Icon::new(Some(Icons::search()))))
14189                        .counter(Text::new("COUNTER")),
14190                )
14191                .build();
14192                tester.pump_widget(
14193                    Center::new()
14194                        .child(SizedBox::new().width(0.0).height(0.0).child(decorator))
14195                        .into_widget(),
14196                );
14197                tester.pump_by(K_TRANSITION_DURATION);
14198
14199                expect(
14200                    tester,
14201                    &find::by_type::<InputDecorator>(),
14202                    finds_one_widget(),
14203                );
14204                assert_eq!(tester.get_size(find::text("COUNTER")), Size::ZERO);
14205            });
14206        }
14207
14208        // input_decorator_test.dart 'Material3 - InputDecoration constraints - No InputDecorator
14209        // constraints'.
14210        #[test]
14211        fn without_constraints_the_decorator_fills_the_width_at_the_default_height() {
14212            test_widgets(|tester| {
14213                pump(tester, BuildInputDecorator::new(InputDecoration::new()));
14214                // Should fill the screen width and be default height.
14215                assert_eq!(
14216                    get_decorator_rect(tester).size(),
14217                    Size::new(800.0, crate::constants::K_MIN_INTERACTIVE_DIMENSION)
14218                );
14219            });
14220        }
14221
14222        fn theme_with_constraints(app: &App) -> ThemeData {
14223            ThemeData::builder()
14224                .input_decoration_theme(InputDecorationThemeData::new().constraints(
14225                    BoxConstraints {
14226                        max_width: 300.0,
14227                        max_height: 40.0,
14228                        ..BoxConstraints::new()
14229                    },
14230                ))
14231                .build(app)
14232        }
14233
14234        // input_decorator_test.dart 'Material3 - InputDecoration constraints -
14235        // InputDecoratorThemeData constraints'.
14236        #[test]
14237        fn the_theme_constraints_apply() {
14238            test_widgets(|tester| {
14239                pump(
14240                    tester,
14241                    BuildInputDecorator::new(InputDecoration::new()).theme(theme_with_constraints),
14242                );
14243                // Theme settings should make it 300x40 pixels.
14244                assert_eq!(get_decorator_rect(tester).size(), Size::new(300.0, 40.0));
14245            });
14246        }
14247
14248        // input_decorator_test.dart 'Material3 - InputDecoration constraints - InputDecorator
14249        // constraints'.
14250        #[test]
14251        fn the_decoration_constraints_override_the_theme() {
14252            test_widgets(|tester| {
14253                pump(
14254                    tester,
14255                    BuildInputDecorator::new(InputDecoration::new().constraints(BoxConstraints {
14256                        max_width: 200.0,
14257                        max_height: 32.0,
14258                        ..BoxConstraints::new()
14259                    }))
14260                    .theme(theme_with_constraints),
14261                );
14262                // InputDecoration.constraints should override the theme. It should be
14263                // only 200x32 pixels.
14264                assert_eq!(get_decorator_rect(tester).size(), Size::new(200.0, 32.0));
14265            });
14266        }
14267
14268        fn prefix_icon() -> IconData {
14269            Icons::search()
14270        }
14271
14272        fn suffix_icon() -> IconData {
14273            Icons::cancel_outlined()
14274        }
14275
14276        /// Dart's `getPrefixIconRect` / `getSuffixIconRect`: the rect of the `Icon`.
14277        fn icon_rect(tester: &WidgetTester, icon: &IconData) -> Rect {
14278            tester.get_rect(find::by_icon(icon))
14279        }
14280
14281        /// Dart's `tester.getRect(findPrefixIconInnerRichText())`.
14282        fn icon_inner_rect(tester: &WidgetTester, icon: &IconData) -> Rect {
14283            tester.get_rect(find::descendant(
14284                find::by_icon(icon),
14285                find::by_type::<RichText>(),
14286            ))
14287        }
14288
14289        /// Dart's `getPrefixIconStyle` / `getSuffixIconStyle`.
14290        fn icon_style(tester: &WidgetTester, icon: &IconData) -> TextStyle {
14291            tester.glyph_style(tester.element(find::by_icon(icon)))
14292        }
14293
14294        fn input_rect(tester: &WidgetTester) -> Rect {
14295            tester.get_rect(find::text(INPUT_TEXT))
14296        }
14297
14298        /// The checks every 'prefixIcon is correctly positioned' case makes, in `text_direction`.
14299        fn check_prefix_icon_position(tester: &WidgetTester, text_direction: TextDirection) {
14300            let icon = prefix_icon();
14301            // By default, the prefix icon is rendered inside a 48x48 constrained box.
14302            assert_eq!(icon_rect(tester, &icon).size(), Size::new(48.0, 48.0));
14303            // The icon size is 24 per Material 3 spec.
14304            assert_eq!(icon_style(tester, &icon).font_size, Some(24.0));
14305            // Prefix icon is vertically centered inside the container.
14306            assert_eq!(
14307                icon_rect(tester, &icon).center().dy(),
14308                get_container_rect(tester).center().dy()
14309            );
14310            let inner = icon_inner_rect(tester, &icon);
14311            match text_direction {
14312                TextDirection::Ltr => {
14313                    // Left padding is 12 per Material 3 spec.
14314                    assert_eq!(inner.left, 12.0);
14315                    // The gap between the icon and the input should be 16 based on M3 specification.
14316                    assert_eq!(input_rect(tester).left - inner.right, 16.0);
14317                }
14318                TextDirection::Rtl => {
14319                    // Right padding is 12 per Material 3 spec.
14320                    assert_eq!(get_decorator_rect(tester).right - inner.right, 12.0);
14321                    assert_eq!(inner.left - input_rect(tester).right, 16.0);
14322                }
14323            }
14324        }
14325
14326        /// The checks every 'suffixIcon is correctly positioned' case makes, in `text_direction`.
14327        fn check_suffix_icon_position(tester: &WidgetTester, text_direction: TextDirection) {
14328            let icon = suffix_icon();
14329            // By default, the suffix icon is rendered inside a 48x48 constrained box.
14330            assert_eq!(icon_rect(tester, &icon).size(), Size::new(48.0, 48.0));
14331            // The icon size is 24 per Material 3 spec.
14332            assert_eq!(icon_style(tester, &icon).font_size, Some(24.0));
14333            // Suffix icon is vertically centered inside the container.
14334            assert_eq!(
14335                icon_rect(tester, &icon).center().dy(),
14336                get_container_rect(tester).center().dy()
14337            );
14338            let inner = icon_inner_rect(tester, &icon);
14339            match text_direction {
14340                TextDirection::Ltr => {
14341                    // Right padding is 12 per Material 3 spec.
14342                    assert_eq!(get_decorator_rect(tester).right - inner.right, 12.0);
14343                    // The gap between the icon and the input should be 16 based on M3 specification.
14344                    assert_eq!(inner.left - input_rect(tester).right, 16.0);
14345                }
14346                TextDirection::Rtl => {
14347                    // Left padding is 12 per Material 3 spec.
14348                    assert_eq!(inner.left, 12.0);
14349                    assert_eq!(input_rect(tester).left - inner.right, 16.0);
14350                }
14351            }
14352        }
14353
14354        fn prefixed(base: InputDecoration) -> InputDecoration {
14355            base.label_text(LABEL_TEXT)
14356                .prefix_icon(Icon::new(Some(prefix_icon())))
14357        }
14358
14359        fn suffixed(base: InputDecoration) -> InputDecoration {
14360            base.label_text(LABEL_TEXT)
14361                .suffix_icon(Icon::new(Some(suffix_icon())))
14362        }
14363
14364        fn check_icon_color(
14365            tester: &mut WidgetTester,
14366            decorator: BuildInputDecorator,
14367            icon: IconData,
14368            color: impl Fn(&ThemeData) -> Color,
14369        ) {
14370            pump(tester, decorator);
14371            let theme = decorator_theme(tester);
14372            assert_eq!(
14373                icon_style(tester, &icon).color.map(|color| *color),
14374                Some(color(&theme))
14375            );
14376        }
14377
14378        fn error(theme: &ThemeData) -> Color {
14379            theme.color_scheme.error()
14380        }
14381
14382        fn on_error_container(theme: &ThemeData) -> Color {
14383            theme.color_scheme.on_error_container()
14384        }
14385
14386        /// One positioned and one colour case of an icon for each of Dart's prefix/suffix groups.
14387        macro_rules! affix_icon_cases {
14388        ($(
14389            $(#[$doc:meta])*
14390            $position:ident: $decorate:ident, $base:expr, |$builder:ident| $configure:expr,
14391                $check:ident, $direction:expr;
14392        )*) => {
14393            $(
14394                $(#[$doc])*
14395                #[test]
14396                fn $position() {
14397                    test_widgets(|tester| {
14398                        let $builder = BuildInputDecorator::new($decorate($base));
14399                        pump(tester, $configure);
14400                        $check(tester, $direction);
14401                    });
14402                }
14403            )*
14404        };
14405    }
14406
14407        affix_icon_cases! {
14408            // input_decorator_test.dart 'Material3 - InputDecoration prefix/suffix - for filled text
14409            // field - when field is enabled - prefixIcon is correctly positioned - LTR'.
14410            filled_enabled_prefix_icon_is_correctly_positioned_ltr: prefixed, filled(),
14411                |b| b, check_prefix_icon_position, TextDirection::Ltr;
14412            // '... - when field is enabled - prefixIcon is correctly positioned - RTL'.
14413            filled_enabled_prefix_icon_is_correctly_positioned_rtl: prefixed, filled(),
14414                |b| b.text_direction(TextDirection::Rtl), check_prefix_icon_position,
14415                TextDirection::Rtl;
14416            // '... - when field is enabled - suffixIcon is correctly positioned - LTR'.
14417            filled_enabled_suffix_icon_is_correctly_positioned_ltr: suffixed, filled(),
14418                |b| b, check_suffix_icon_position, TextDirection::Ltr;
14419            // '... - when field is enabled - suffixIcon is correctly positioned - RTL'.
14420            filled_enabled_suffix_icon_is_correctly_positioned_rtl: suffixed, filled(),
14421                |b| b.text_direction(TextDirection::Rtl), check_suffix_icon_position,
14422                TextDirection::Rtl;
14423            // '... for filled text field - when field is disabled - prefixIcon is correctly
14424            // positioned'.
14425            filled_disabled_prefix_icon_is_correctly_positioned: prefixed, filled().enabled(false),
14426                |b| b, check_prefix_icon_position, TextDirection::Ltr;
14427            // '... for filled text field - when field is disabled - suffixIcon is correctly
14428            // positioned'.
14429            filled_disabled_suffix_icon_is_correctly_positioned: suffixed, filled().enabled(false),
14430                |b| b, check_suffix_icon_position, TextDirection::Ltr;
14431            // '... for filled text field - when field is hovered - prefixIcon is correctly
14432            // positioned'.
14433            filled_hovered_prefix_icon_is_correctly_positioned: prefixed, filled(),
14434                |b| b.is_hovering(true), check_prefix_icon_position, TextDirection::Ltr;
14435            // '... for filled text field - when field is hovered - suffixIcon is correctly
14436            // positioned'.
14437            filled_hovered_suffix_icon_is_correctly_positioned: suffixed, filled(),
14438                |b| b.is_hovering(true), check_suffix_icon_position, TextDirection::Ltr;
14439            // '... for filled text field - when field is focused - prefixIcon is correctly
14440            // positioned'.
14441            filled_focused_prefix_icon_is_correctly_positioned: prefixed, filled(),
14442                |b| b.is_focused(true), check_prefix_icon_position, TextDirection::Ltr;
14443            // '... for filled text field - when field is focused - suffixIcon is correctly
14444            // positioned'.
14445            filled_focused_suffix_icon_is_correctly_positioned: suffixed, filled(),
14446                |b| b.is_focused(true), check_suffix_icon_position, TextDirection::Ltr;
14447            // '... for filled text field - when field is in error - prefixIcon is correctly
14448            // positioned'.
14449            filled_error_prefix_icon_is_correctly_positioned: prefixed, filled().error_text(ERROR_TEXT),
14450                |b| b, check_prefix_icon_position, TextDirection::Ltr;
14451            // '... for filled text field - when field is in error - suffixIcon is correctly
14452            // positioned'.
14453            filled_error_suffix_icon_is_correctly_positioned: suffixed, filled().error_text(ERROR_TEXT),
14454                |b| b, check_suffix_icon_position, TextDirection::Ltr;
14455            // '... for outlined text field - when field is enabled - prefixIcon is correctly
14456            // positioned'.
14457            outlined_enabled_prefix_icon_is_correctly_positioned: prefixed, outlined(),
14458                |b| b, check_prefix_icon_position, TextDirection::Ltr;
14459            // '... for outlined text field - when field is enabled - suffixIcon is correctly
14460            // positioned'.
14461            outlined_enabled_suffix_icon_is_correctly_positioned: suffixed, outlined(),
14462                |b| b, check_suffix_icon_position, TextDirection::Ltr;
14463            // '... for outlined text field - when field is disabled - prefixIcon is correctly
14464            // positioned'.
14465            outlined_disabled_prefix_icon_is_correctly_positioned: prefixed, outlined().enabled(false),
14466                |b| b, check_prefix_icon_position, TextDirection::Ltr;
14467            // '... for outlined text field - when field is disabled - suffixIcon is correctly
14468            // positioned'.
14469            outlined_disabled_suffix_icon_is_correctly_positioned: suffixed, outlined().enabled(false),
14470                |b| b, check_suffix_icon_position, TextDirection::Ltr;
14471            // '... for outlined text field - when field is hovered - prefixIcon is correctly
14472            // positioned'.
14473            outlined_hovered_prefix_icon_is_correctly_positioned: prefixed, outlined(),
14474                |b| b.is_hovering(true), check_prefix_icon_position, TextDirection::Ltr;
14475            // '... for outlined text field - when field is hovered - suffixIcon is correctly
14476            // positioned'.
14477            outlined_hovered_suffix_icon_is_correctly_positioned: suffixed, outlined(),
14478                |b| b.is_hovering(true), check_suffix_icon_position, TextDirection::Ltr;
14479            // '... for outlined text field - when field is focused - prefixIcon is correctly
14480            // positioned'.
14481            outlined_focused_prefix_icon_is_correctly_positioned: prefixed, outlined(),
14482                |b| b.is_focused(true), check_prefix_icon_position, TextDirection::Ltr;
14483            // '... for outlined text field - when field is focused - suffixIcon is correctly
14484            // positioned'.
14485            outlined_focused_suffix_icon_is_correctly_positioned: suffixed, outlined(),
14486                |b| b.is_focused(true), check_suffix_icon_position, TextDirection::Ltr;
14487            // '... for outlined text field - when field is in error - prefixIcon is correctly
14488            // positioned'.
14489            outlined_error_prefix_icon_is_correctly_positioned: prefixed,
14490                outlined().error_text(ERROR_TEXT), |b| b, check_prefix_icon_position,
14491                TextDirection::Ltr;
14492            // '... for outlined text field - when field is in error - suffixIcon is correctly
14493            // positioned'.
14494            outlined_error_suffix_icon_is_correctly_positioned: suffixed,
14495                outlined().error_text(ERROR_TEXT), |b| b, check_suffix_icon_position,
14496                TextDirection::Ltr;
14497        }
14498
14499        /// One 'has correct color' case of Dart's prefix/suffix groups.
14500        macro_rules! affix_icon_color_cases {
14501        ($(
14502            $name:ident: $decorate:ident, $base:expr, |$builder:ident| $configure:expr,
14503                $icon:expr, $color:expr;
14504        )*) => {
14505            $(
14506                #[test]
14507                fn $name() {
14508                    test_widgets(|tester| {
14509                        let $builder = BuildInputDecorator::new($decorate($base));
14510                        check_icon_color(tester, $configure, $icon, $color);
14511                    });
14512                }
14513            )*
14514        };
14515    }
14516
14517        // input_decorator_test.dart 'Material3 - InputDecoration prefix/suffix - for filled text
14518        // field' and 'for outlined text field', each state's 'prefixIcon has correct color',
14519        // 'suffixIcon has correct color' and, in error, '... has correct color when hovered'.
14520        affix_icon_color_cases! {
14521            filled_enabled_prefix_icon_has_correct_color: prefixed, filled(), |b| b,
14522                prefix_icon(), on_surface_variant;
14523            filled_enabled_suffix_icon_has_correct_color: suffixed, filled(), |b| b,
14524                suffix_icon(), on_surface_variant;
14525            filled_disabled_prefix_icon_has_correct_color: prefixed, filled().enabled(false), |b| b,
14526                prefix_icon(), disabled_on_surface;
14527            filled_disabled_suffix_icon_has_correct_color: suffixed, filled().enabled(false), |b| b,
14528                suffix_icon(), disabled_on_surface;
14529            filled_hovered_prefix_icon_has_correct_color: prefixed, filled(), |b| b.is_hovering(true),
14530                prefix_icon(), on_surface_variant;
14531            filled_hovered_suffix_icon_has_correct_color: suffixed, filled(), |b| b.is_hovering(true),
14532                suffix_icon(), on_surface_variant;
14533            filled_focused_prefix_icon_has_correct_color: prefixed, filled(), |b| b.is_focused(true),
14534                prefix_icon(), on_surface_variant;
14535            filled_focused_suffix_icon_has_correct_color: suffixed, filled(), |b| b.is_focused(true),
14536                suffix_icon(), on_surface_variant;
14537            filled_error_prefix_icon_has_correct_color: prefixed, filled().error_text(ERROR_TEXT),
14538                |b| b, prefix_icon(), on_surface_variant;
14539            filled_error_prefix_icon_has_correct_color_when_hovered: prefixed,
14540                filled().error_text(ERROR_TEXT), |b| b.is_hovering(true), prefix_icon(),
14541                on_surface_variant;
14542            filled_error_suffix_icon_has_correct_color: suffixed, filled().error_text(ERROR_TEXT),
14543                |b| b, suffix_icon(), error;
14544            filled_error_suffix_icon_has_correct_color_when_hovered: suffixed,
14545                filled().error_text(ERROR_TEXT), |b| b.is_hovering(true), suffix_icon(),
14546                on_error_container;
14547            outlined_enabled_prefix_icon_has_correct_color: prefixed, outlined(), |b| b,
14548                prefix_icon(), on_surface_variant;
14549            outlined_enabled_suffix_icon_has_correct_color: suffixed, outlined(), |b| b,
14550                suffix_icon(), on_surface_variant;
14551            outlined_disabled_prefix_icon_has_correct_color: prefixed, outlined().enabled(false),
14552                |b| b, prefix_icon(), disabled_on_surface;
14553            outlined_disabled_suffix_icon_has_correct_color: suffixed, outlined().enabled(false),
14554                |b| b, suffix_icon(), disabled_on_surface;
14555            outlined_hovered_prefix_icon_has_correct_color: prefixed, outlined(),
14556                |b| b.is_hovering(true), prefix_icon(), on_surface_variant;
14557            outlined_hovered_suffix_icon_has_correct_color: suffixed, outlined(),
14558                |b| b.is_hovering(true), suffix_icon(), on_surface_variant;
14559            outlined_focused_prefix_icon_has_correct_color: prefixed, outlined(),
14560                |b| b.is_focused(true), prefix_icon(), on_surface_variant;
14561            outlined_focused_suffix_icon_has_correct_color: suffixed, outlined(),
14562                |b| b.is_focused(true), suffix_icon(), on_surface_variant;
14563            outlined_error_prefix_icon_has_correct_color: prefixed, outlined().error_text(ERROR_TEXT),
14564                |b| b, prefix_icon(), on_surface_variant;
14565            outlined_error_prefix_icon_has_correct_color_when_hovered: prefixed,
14566                outlined().error_text(ERROR_TEXT), |b| b.is_hovering(true), prefix_icon(),
14567                on_surface_variant;
14568            outlined_error_suffix_icon_has_correct_color: suffixed, outlined().error_text(ERROR_TEXT),
14569                |b| b, suffix_icon(), error;
14570            outlined_error_suffix_icon_has_correct_color_when_hovered: suffixed,
14571                outlined().error_text(ERROR_TEXT), |b| b.is_hovering(true), suffix_icon(),
14572                on_error_container;
14573        }
14574
14575        /// The colour of the nearest `IconTheme` above the `Icon` showing `icon`: Dart's
14576        /// `tester.widget<IconTheme>(find.widgetWithIcon(IconTheme, icon).first).data.color`.
14577        fn icon_theme_color(tester: &WidgetTester, icon: &IconData) -> Option<Color> {
14578            let icon_element = tester.element(find::by_icon(icon));
14579            let icon_theme = tester
14580                .ancestors(icon_element)
14581                .into_iter()
14582                .find(|element| {
14583                    let app = tester.cell.borrow();
14584                    downcast_widget::<waft_widgets::IconTheme>(&**element.widget(&app)).is_some()
14585                })
14586                .expect("an IconTheme above the icon");
14587            tester.widget(icon_theme, |theme: &waft_widgets::IconTheme| {
14588                theme.data.color.as_ref().map(|color| **color)
14589            })
14590        }
14591
14592        // input_decorator_test.dart 'Material3 - InputDecoration prefix/suffix - InputDecorator
14593        // iconColor/prefixIconColor/suffixIconColor', on an `InputDecorator` where Dart uses the
14594        // `TextField` that builds one.
14595        #[test]
14596        fn the_icon_colors_reach_the_icon_themes() {
14597            test_widgets(|tester| {
14598                pump(
14599                    tester,
14600                    BuildInputDecorator::new(
14601                        InputDecoration::new()
14602                            .icon(Icon::new(Some(Icons::cabin())))
14603                            .prefix_icon(Icon::new(Some(Icons::sailing())))
14604                            .suffix_icon(Icon::new(Some(Icons::close())))
14605                            .icon_color(crate::colors::Colors::AMBER.primary())
14606                            .prefix_icon_color(crate::colors::Colors::GREEN.primary())
14607                            .suffix_icon_color(crate::colors::Colors::RED.primary())
14608                            .filled(true),
14609                    ),
14610                );
14611                assert_eq!(
14612                    icon_theme_color(tester, &Icons::cabin()),
14613                    Some(crate::colors::Colors::AMBER.primary())
14614                );
14615                assert_eq!(
14616                    icon_theme_color(tester, &Icons::sailing()),
14617                    Some(crate::colors::Colors::GREEN.primary())
14618                );
14619                assert_eq!(
14620                    icon_theme_color(tester, &Icons::close()),
14621                    Some(crate::colors::Colors::RED.primary())
14622                );
14623            });
14624        }
14625
14626        /// The target opacity of the `AnimatedOpacity` above the only `Icon`.
14627        fn affix_opacity(tester: &WidgetTester) -> f64 {
14628            let icon = tester.element(find::by_type::<Icon>());
14629            let opacity = tester
14630                .ancestors(icon)
14631                .into_iter()
14632                .find(|element| {
14633                    let app = tester.cell.borrow();
14634                    downcast_widget::<AnimatedOpacity>(&**element.widget(&app)).is_some()
14635                })
14636                .expect("an AnimatedOpacity above the icon");
14637            tester.widget(opacity, |opacity: &AnimatedOpacity| opacity.opacity)
14638        }
14639
14640        /// Dart's 'Prefix/Suffix ignores pointer when hidden' on an `InputDecorator`: the
14641        /// `TextField` Dart taps to focus becomes a rebuild with `is_focused`.
14642        fn check_affix_ignores_pointer_when_hidden(
14643            tester: &mut WidgetTester,
14644            affix: fn(InputDecoration, WidgetRef) -> InputDecoration,
14645        ) {
14646            let tapped = Rc::new(Cell::new(false));
14647            let build = |is_focused: bool| {
14648                let tapped = Rc::clone(&tapped);
14649                let affix_widget = GestureDetector::new()
14650                    .on_tap(Listener::new(move |_app| tapped.set(true)))
14651                    .child(Icon::new(Some(Icons::search())))
14652                    .into_widget();
14653                BuildInputDecorator::new(affix(
14654                    InputDecoration::new().label_text("label"),
14655                    affix_widget,
14656                ))
14657                .is_empty(true)
14658                .is_focused(is_focused)
14659                .build()
14660            };
14661            tester.pump_widget(build(false));
14662            assert!(!tapped.get());
14663
14664            // Initially the affix icon should be hidden.
14665            assert_eq!(affix_opacity(tester), 0.0);
14666
14667            let icon_center = tester.get_rect(find::by_type::<Icon>()).center();
14668            tester.tap_at(icon_center, 1);
14669            tester.pump();
14670
14671            // The affix icon should ignore pointer events when hidden.
14672            assert!(!tapped.get());
14673
14674            // Focus the decorator to show the affix icon.
14675            tester.pump_widget(build(true));
14676
14677            // The affix icon should be visible.
14678            assert_eq!(affix_opacity(tester), 1.0);
14679
14680            // Tap the affix icon.
14681            let icon_center = tester.get_rect(find::by_type::<Icon>()).center();
14682            tester.tap_at(icon_center, 2);
14683            tester.pump();
14684
14685            // The affix icon should be tapped.
14686            assert!(tapped.get());
14687        }
14688
14689        // input_decorator_test.dart 'Material3 - InputDecoration prefix/suffix - Prefix ignores
14690        // pointer when hidden'.
14691        #[test]
14692        fn the_prefix_ignores_the_pointer_when_hidden() {
14693            test_widgets(|tester| {
14694                check_affix_ignores_pointer_when_hidden(tester, |decoration, prefix| {
14695                    decoration.prefix(prefix)
14696                })
14697            });
14698        }
14699
14700        // input_decorator_test.dart 'Material3 - InputDecoration prefix/suffix - Suffix ignores
14701        // pointer when hidden'.
14702        #[test]
14703        fn the_suffix_ignores_the_pointer_when_hidden() {
14704            test_widgets(|tester| {
14705                check_affix_ignores_pointer_when_hidden(tester, |decoration, suffix| {
14706                    decoration.suffix(suffix)
14707                })
14708            });
14709        }
14710
14711        /// Dart's `getHintOpacity(tester)`: the value of the first `FadeTransition` above the hint.
14712        fn hint_opacity(tester: &WidgetTester) -> f64 {
14713            let hint = tester.element(find::text(HINT_TEXT));
14714            let fade = tester
14715                .ancestors(hint)
14716                .into_iter()
14717                .find(|element| {
14718                    let app = tester.cell.borrow();
14719                    downcast_widget::<FadeTransition>(&**element.widget(&app)).is_some()
14720                })
14721                .expect("a FadeTransition above the hint");
14722            let opacity = tester.widget(fade, |fade: &FadeTransition| fade.opacity.clone());
14723            opacity.value(&tester.cell.borrow())
14724        }
14725
14726        fn collapsed() -> InputDecoration {
14727            InputDecoration::collapsed(None).hint_text(HINT_TEXT)
14728        }
14729
14730        // Overall height for a collapsed InputDecorator is 24dp which is the input
14731        // height (font size = 16, line height = 1.5).
14732        const COLLAPSED_INPUT_HEIGHT: f64 = 24.0;
14733
14734        fn check_collapsed_height(tester: &mut WidgetTester) {
14735            tester.pump_widget(BuildInputDecorator::new(collapsed()).build());
14736
14737            assert_eq!(
14738                get_decorator_rect(tester).size(),
14739                Size::new(800.0, COLLAPSED_INPUT_HEIGHT)
14740            );
14741            assert_eq!(input_rect(tester).height(), COLLAPSED_INPUT_HEIGHT);
14742            assert_eq!(input_rect(tester).top, 0.0);
14743            assert_eq!(hint_opacity(tester), 0.0);
14744
14745            // The hint should appear.
14746            tester.pump_widget(
14747                BuildInputDecorator::new(collapsed())
14748                    .is_empty(true)
14749                    .is_focused(true)
14750                    .build(),
14751            );
14752            tester.pump_and_settle();
14753
14754            assert_eq!(
14755                get_decorator_rect(tester).size(),
14756                Size::new(800.0, COLLAPSED_INPUT_HEIGHT)
14757            );
14758            assert_eq!(input_rect(tester).height(), COLLAPSED_INPUT_HEIGHT);
14759            assert_eq!(input_rect(tester).top, 0.0);
14760            assert_eq!(hint_opacity(tester), 1.0);
14761            assert_eq!(
14762                tester.get_rect(find::text(HINT_TEXT)).height(),
14763                COLLAPSED_INPUT_HEIGHT
14764            );
14765            assert_eq!(tester.get_rect(find::text(HINT_TEXT)).top, 0.0);
14766        }
14767
14768        // input_decorator_test.dart 'Material3 - InputDecoration collapsed - Decoration height is
14769        // set to input height on mobile' (TargetPlatformVariant.mobile()).
14770        #[test]
14771        fn a_collapsed_decoration_is_the_input_height_on_mobile() {
14772            test_widgets_variant(TargetPlatformVariant::mobile(), check_collapsed_height);
14773        }
14774
14775        // input_decorator_test.dart 'Material3 - InputDecoration collapsed - Decoration height is
14776        // set to input height on desktop' (TargetPlatformVariant.desktop()).
14777        #[test]
14778        fn a_collapsed_decoration_is_the_input_height_on_desktop() {
14779            test_widgets_variant(TargetPlatformVariant::desktop(), check_collapsed_height);
14780        }
14781
14782        // input_decorator_test.dart 'Material3 - InputDecoration collapsed -
14783        // InputDecoration.collapsed defaults to no border'.
14784        #[test]
14785        fn a_collapsed_decoration_has_no_border() {
14786            test_widgets(|tester| {
14787                pump(
14788                    tester,
14789                    BuildInputDecorator::new(InputDecoration::collapsed(Some(
14790                        HINT_TEXT.to_owned(),
14791                    ))),
14792                );
14793                assert_eq!(get_border_weight(tester), 0.0);
14794            });
14795        }
14796
14797        // input_decorator_test.dart 'Material3 - InputDecoration collapsed -
14798        // InputDecoration.collapsed accepts constraints'.
14799        #[test]
14800        fn a_collapsed_decoration_takes_constraints() {
14801            test_widgets(|tester| {
14802                pump(
14803                    tester,
14804                    BuildInputDecorator::new(
14805                        InputDecoration::collapsed(Some(HINT_TEXT.to_owned()))
14806                            .constraints(BoxConstraints::tight_for(Some(200.0), Some(32.0))),
14807                    ),
14808                );
14809                assert_eq!(get_decorator_rect(tester).size(), Size::new(200.0, 32.0));
14810            });
14811        }
14812
14813        // input_decorator_test.dart 'Material3 - InputDecoration collapsed -
14814        // InputDecoration.collapsed accepts hintMaxLines'.
14815        #[test]
14816        fn a_collapsed_decoration_takes_hint_max_lines() {
14817            test_widgets(|tester| {
14818                pump(
14819                    tester,
14820                    BuildInputDecorator::new(
14821                        InputDecoration::collapsed(Some(THREE_LINES.to_owned())).hint_max_lines(2),
14822                    ),
14823                );
14824                const HINT_LINE_HEIGHT: f64 = 24.0; // font size = 16 and font height = 1.5.
14825                assert_eq!(
14826                    get_decorator_rect(tester).size(),
14827                    Size::new(800.0, 2.0 * HINT_LINE_HEIGHT)
14828                );
14829            });
14830        }
14831
14832        // input_decorator_test.dart 'Material3 - InputDecoration collapsed -
14833        // InputDecoration.collapsed accepts hintFadeDuration'.
14834        #[test]
14835        fn a_collapsed_decoration_takes_hint_fade_duration() {
14836            test_widgets(|tester| {
14837                let decoration = || collapsed().hint_fade_duration(Duration::from_millis(120));
14838                // Build once with empty content.
14839                tester.pump_widget(
14840                    BuildInputDecorator::new(decoration())
14841                        .is_empty(true)
14842                        .build(),
14843                );
14844
14845                // Hint is visible (opacity 1.0).
14846                assert_eq!(hint_opacity(tester), 1.0);
14847
14848                // Rebuild with non-empty content.
14849                tester.pump_widget(BuildInputDecorator::new(decoration()).build());
14850
14851                // The hint's opacity animates from 1.0 to 0.0.
14852                // The animation's default duration is 20ms.
14853                tester.pump_by(Duration::from_millis(50));
14854                let hint_opacity_50ms = hint_opacity(tester);
14855                assert!(hint_opacity_50ms > 0.0 && hint_opacity_50ms < 1.0);
14856                tester.pump_by(Duration::from_millis(50));
14857                let hint_opacity_100ms = hint_opacity(tester);
14858                assert!(hint_opacity_100ms > 0.0 && hint_opacity_100ms < hint_opacity_50ms);
14859                tester.pump_by(Duration::from_millis(50));
14860                assert_eq!(hint_opacity(tester), 0.0);
14861            });
14862        }
14863
14864        /// Dart's `buildInputDecoratorWithFloatingLabel`, the label a text.
14865        fn floating_label_decorator(
14866            text_direction: TextDirection,
14867            has_icon: bool,
14868            alignment: FloatingLabelAlignment,
14869            border_is_outline: bool,
14870        ) -> WidgetRef {
14871            let mut decoration = InputDecoration::new()
14872                .content_padding(EdgeInsetsGeometry::directional(40.0, 12.0, 0.0, 12.0))
14873                .floating_label_alignment(alignment)
14874                .label_text(LABEL_TEXT)
14875                .hint_text(HINT_TEXT)
14876                .filled(true);
14877            if has_icon {
14878                decoration = decoration.icon(Icon::new(Some(Icons::insert_link())));
14879            }
14880            if border_is_outline {
14881                decoration = decoration.border(OutlineInputBorder::new());
14882            }
14883            BuildInputDecorator::new(decoration)
14884                .text_direction(text_direction)
14885                .build()
14886        }
14887
14888        /// Pumps the filled and then the outlined frame of a floatingLabelAlignment case and
14889        /// checks each with `check`.
14890        fn check_floating_label(
14891            tester: &mut WidgetTester,
14892            text_direction: TextDirection,
14893            has_icon: bool,
14894            alignment: FloatingLabelAlignment,
14895            check: impl Fn(Rect),
14896        ) {
14897            for border_is_outline in [false, true] {
14898                tester.pump_widget(floating_label_decorator(
14899                    text_direction,
14900                    has_icon,
14901                    alignment,
14902                    border_is_outline,
14903                ));
14904                check(get_label_rect(tester));
14905            }
14906        }
14907
14908        // input_decorator_test.dart 'Material3 - InputDecoration floatingLabelAlignment - LTR with
14909        // icon aligned - start'.
14910        #[test]
14911        fn ltr_with_an_icon_the_floating_label_aligns_to_the_start() {
14912            test_widgets(|tester| {
14913                check_floating_label(
14914                    tester,
14915                    TextDirection::Ltr,
14916                    true,
14917                    FloatingLabelAlignment::START,
14918                    // icon (40) + contentPadding (40) + _kInputExtraPadding
14919                    |label| assert_eq!(label.left, 84.0),
14920                );
14921            });
14922        }
14923
14924        // input_decorator_test.dart '... - LTR with icon aligned - center'.
14925        #[test]
14926        fn ltr_with_an_icon_the_floating_label_aligns_to_the_center() {
14927            test_widgets(|tester| {
14928                check_floating_label(
14929                    tester,
14930                    TextDirection::Ltr,
14931                    true,
14932                    FloatingLabelAlignment::CENTER,
14933                    // icon (40) + (decorator (800) - icon (40)) / 2
14934                    |label| assert_eq!(label.center().dx(), 420.0),
14935                );
14936            });
14937        }
14938
14939        // input_decorator_test.dart '... - LTR without icon aligned - start'.
14940        #[test]
14941        fn ltr_without_an_icon_the_floating_label_aligns_to_the_start() {
14942            test_widgets(|tester| {
14943                check_floating_label(
14944                    tester,
14945                    TextDirection::Ltr,
14946                    false,
14947                    FloatingLabelAlignment::START,
14948                    // contentPadding (40) + _kInputExtraPadding
14949                    |label| assert_eq!(label.left, 44.0),
14950                );
14951            });
14952        }
14953
14954        // input_decorator_test.dart '... - LTR without icon aligned - center'.
14955        #[test]
14956        fn ltr_without_an_icon_the_floating_label_aligns_to_the_center() {
14957            test_widgets(|tester| {
14958                check_floating_label(
14959                    tester,
14960                    TextDirection::Ltr,
14961                    false,
14962                    FloatingLabelAlignment::CENTER,
14963                    // decorator (800) / 2
14964                    |label| assert_eq!(label.center().dx(), 400.0),
14965                );
14966            });
14967        }
14968
14969        // input_decorator_test.dart '... - RTL with icon aligned - start'.
14970        #[test]
14971        fn rtl_with_an_icon_the_floating_label_aligns_to_the_start() {
14972            test_widgets(|tester| {
14973                check_floating_label(
14974                    tester,
14975                    TextDirection::Rtl,
14976                    true,
14977                    FloatingLabelAlignment::START,
14978                    // decorator (800) - icon (40) - contentPadding (40) - _kInputExtraPadding
14979                    |label| assert_eq!(label.right, 716.0),
14980                );
14981            });
14982        }
14983
14984        // input_decorator_test.dart '... - RTL with icon aligned - center'.
14985        #[test]
14986        fn rtl_with_an_icon_the_floating_label_aligns_to_the_center() {
14987            test_widgets(|tester| {
14988                check_floating_label(
14989                    tester,
14990                    TextDirection::Rtl,
14991                    true,
14992                    FloatingLabelAlignment::CENTER,
14993                    // (decorator (800) - icon (40)) / 2
14994                    |label| assert_eq!(label.center().dx(), 380.0),
14995                );
14996            });
14997        }
14998
14999        // input_decorator_test.dart '... - RTL without icon aligned - start'.
15000        #[test]
15001        fn rtl_without_an_icon_the_floating_label_aligns_to_the_start() {
15002            test_widgets(|tester| {
15003                check_floating_label(
15004                    tester,
15005                    TextDirection::Rtl,
15006                    false,
15007                    FloatingLabelAlignment::START,
15008                    // decorator (800) - contentPadding (40) - _kInputExtraPadding
15009                    |label| assert_eq!(label.right, 756.0),
15010                );
15011            });
15012        }
15013
15014        // input_decorator_test.dart '... - RTL without icon aligned - center'.
15015        #[test]
15016        fn rtl_without_an_icon_the_floating_label_aligns_to_the_center() {
15017            test_widgets(|tester| {
15018                check_floating_label(
15019                    tester,
15020                    TextDirection::Rtl,
15021                    false,
15022                    FloatingLabelAlignment::CENTER,
15023                    // decorator (800) / 2
15024                    |label| assert_eq!(label.center().dx(), 400.0),
15025                );
15026            });
15027        }
15028
15029        // M3 extra horizontal padding.
15030        const K_INPUT_EXTRA_PADDING: f64 = 4.0;
15031
15032        // input_decorator_test.dart 'Material3 - InputDecoration isDense - Dense layout for an
15033        // outlined decoration'.
15034        #[test]
15035        fn the_dense_layout_of_an_outlined_decoration() {
15036            test_widgets(|tester| {
15037                pump(
15038                    tester,
15039                    BuildInputDecorator::new(outlined().label_text(LABEL_TEXT).is_dense(true)),
15040                );
15041                let container_rect = get_container_rect(tester);
15042                let input_rect = input_rect(tester);
15043
15044                // Content padding is EdgeInsetsDirectional.fromSTEB(12.0, 16.0, 12.0, 8.0).
15045                // Vertical padding affects the container height not the input vertical
15046                // position as the input is centered.
15047                assert_eq!(container_rect.height(), 48.0);
15048                assert_eq!(input_rect.center().dy(), container_rect.center().dy());
15049                assert_eq!(
15050                    input_rect.left,
15051                    container_rect.left + 12.0 + K_INPUT_EXTRA_PADDING
15052                );
15053                assert_eq!(
15054                    input_rect.right,
15055                    container_rect.right - 12.0 - K_INPUT_EXTRA_PADDING
15056                );
15057            });
15058        }
15059
15060        // input_decorator_test.dart 'Material3 - InputDecoration isDense - Dense layout for a filled
15061        // and non-outlined decoration'.
15062        #[test]
15063        fn the_dense_layout_of_a_filled_decoration() {
15064            test_widgets(|tester| {
15065                pump(
15066                    tester,
15067                    BuildInputDecorator::new(filled().label_text(LABEL_TEXT).is_dense(true)),
15068                );
15069                let container_rect = get_container_rect(tester);
15070                let input_rect = input_rect(tester);
15071                let label_rect = get_label_rect(tester);
15072
15073                // Content padding is EdgeInsetsDirectional.fromSTEB(12.0, 4.0, 12.0, 4.0).
15074                assert_eq!(container_rect.height(), 48.0);
15075                assert_eq!(label_rect.top, container_rect.top + 4.0);
15076                assert_eq!(input_rect.bottom, container_rect.bottom - 4.0);
15077                assert_eq!(
15078                    input_rect.left,
15079                    container_rect.left + 12.0 + K_INPUT_EXTRA_PADDING
15080                );
15081                assert_eq!(
15082                    input_rect.right,
15083                    container_rect.right - 12.0 - K_INPUT_EXTRA_PADDING
15084                );
15085            });
15086        }
15087
15088        // input_decorator_test.dart 'Material3 - InputDecoration isDense - Dense layout for a
15089        // non-filled and non-outlined decoration'.
15090        #[test]
15091        fn the_dense_layout_of_an_unfilled_underlined_decoration() {
15092            test_widgets(|tester| {
15093                pump(
15094                    tester,
15095                    BuildInputDecorator::new(
15096                        InputDecoration::new().label_text(LABEL_TEXT).is_dense(true),
15097                    ),
15098                );
15099                let container_rect = get_container_rect(tester);
15100                let input_rect = input_rect(tester);
15101                let label_rect = get_label_rect(tester);
15102
15103                // Content padding is EdgeInsetsDirectional.fromSTEB(0.0, 4.0, 0.0, 4.0).
15104                assert_eq!(container_rect.height(), 48.0);
15105                assert_eq!(label_rect.top, container_rect.top + 4.0);
15106                assert_eq!(input_rect.bottom, container_rect.bottom - 4.0);
15107                assert_eq!(input_rect.left, container_rect.left);
15108                assert_eq!(input_rect.right, container_rect.right);
15109            });
15110        }
15111
15112        // input_decorator_test.dart 'Material3 - InputDecoration isDense - Ambient theme is used'.
15113        #[test]
15114        fn the_ambient_theme_is_dense() {
15115            test_widgets(|tester| {
15116                pump(
15117                    tester,
15118                    BuildInputDecorator::new(InputDecoration::new().label_text(LABEL_TEXT))
15119                        .input_decoration_theme(InputDecorationThemeData::new().is_dense(true)),
15120                );
15121                assert_eq!(get_container_rect(tester).height(), 48.0);
15122            });
15123        }
15124
15125        // input_decorator_test.dart 'InputDecorator.debugDescribeChildren': the part that holds
15126        // without diagnostics, the decoration's eleven children, one per slot.
15127        #[test]
15128        fn a_decoration_with_every_slot_has_eleven_children() {
15129            test_widgets(|tester| {
15130                pump(
15131                    tester,
15132                    BuildInputDecorator::new(
15133                        InputDecoration::new()
15134                            .icon(Text::new("icon"))
15135                            .label_text("label")
15136                            .hint_text("hint")
15137                            .prefix_text("prefix")
15138                            .suffix_text("suffix")
15139                            .prefix_icon(Text::new("prefixIcon"))
15140                            .suffix_icon(Text::new("suffixIcon"))
15141                            .helper_text("helper")
15142                            .counter_text("counter"),
15143                    )
15144                    .child(Text::new("text")),
15145                );
15146                let render = tester.first::<RenderDecoration>();
15147                let app = tester.cell.borrow();
15148                let children = SlottedContainerRenderObjectMixin::children(render, &app);
15149                assert_eq!(children.len(), 11);
15150                for (index, child) in children.iter().enumerate() {
15151                    assert!(
15152                        !children[..index].contains(child),
15153                        "each slot has its own child"
15154                    );
15155                }
15156            });
15157        }
15158    }
15159
15160    // input_decorator_test.dart's cases on themes, widget-state values, intrinsics, the local
15161    // theme's overrides, icon button themes and custom borders.
15162    mod themes_and_intrinsics {
15163        use std::time::Duration;
15164        use waft_painting::OutlinedBorderRef;
15165        use waft_widgets::testing::{TestPointer, WidgetTester, test_widgets};
15166
15167        use crate::test_support::PaintInspection;
15168        use waft_embedder::{Color, Offset, Radius, Size};
15169        use waft_foundation::Listener;
15170        use waft_painting::{
15171            AlignmentGeometry, BorderRadius, BorderSide, EdgeInsets, EdgeInsetsDirectional,
15172            EdgeInsetsGeometry, RoundedRectangleBorder, ShapeBorder, TextDirection, TextStyle,
15173        };
15174        use waft_rendering::BoxConstraints;
15175        use waft_widgets::{
15176            Builder, Center, Column, ConstrainedBox, CrossAxisAlignment, Directionality, Expanded,
15177            FadeTransition, GlobalKey, Icon, IconData, IconTheme, IntoWidget, IntrinsicHeight,
15178            MainAxisSize, RichText, Row, SizedBox, Text, UnconstrainedBox, WidgetRef, WidgetState,
15179            WidgetStateProperty, WidgetStatePropertyAll, WidgetStatePropertyRef,
15180            WidgetStateTextStyle, WidgetStates,
15181        };
15182
15183        use super::super::*;
15184        use super::common::K_TRANSITION_DURATION;
15185        use super::common::*;
15186        use crate::app::MaterialApp;
15187        use crate::button_style::ButtonStyle;
15188        use crate::colors::Colors;
15189        use crate::icon_button::IconButton;
15190        use crate::icon_button_theme::{IconButtonTheme, IconButtonThemeData};
15191        use crate::icons::Icons;
15192        use crate::input_border::{InputBorderRef, OutlineInputBorder};
15193        use crate::material::Material;
15194        use crate::material_state::WidgetStateInputBorder;
15195        use crate::scaffold::Scaffold;
15196        use crate::theme::Theme;
15197        use crate::theme_data::VisualDensity;
15198
15199        fn noop() -> Listener {
15200            Listener::new(|_app| {})
15201        }
15202
15203        fn icon(icon: IconData) -> Icon {
15204            Icon::new(Some(icon))
15205        }
15206
15207        /// The effective style of the `RichText` a `Text` showing `text` builds: Dart's
15208        /// `tester.widget<RichText>(find.descendant(of: find.text(text), matching:
15209        /// find.byType(RichText))).text.style!`.
15210        fn rich_text_style(tester: &WidgetTester, text: &str) -> TextStyle {
15211            let rich_text = tester.element(find::descendant(
15212                find::text(text),
15213                find::by_type::<RichText>(),
15214            ));
15215            tester.widget(rich_text, |rich_text: &RichText| {
15216                rich_text.text.style().cloned().expect("a styled text")
15217            })
15218        }
15219
15220        fn style_color(style: &TextStyle) -> Option<Color> {
15221            style.color.as_ref().map(|color| color.color())
15222        }
15223
15224        /// Dart's `getOpacity(tester, text)`: the value of the nearest `FadeTransition` above the
15225        /// `Text` showing `text`.
15226        fn get_opacity(tester: &WidgetTester, text: &str) -> f64 {
15227            let found = tester.element(find::text(text));
15228            let fade = tester
15229                .ancestors(found)
15230                .into_iter()
15231                .find(|element| {
15232                    let app = tester.cell.borrow();
15233                    waft_widgets::downcast_widget::<FadeTransition>(&**element.widget(&app))
15234                        .is_some()
15235                })
15236                .expect("a FadeTransition above the text");
15237            let opacity = tester.widget(fade, |fade: &FadeTransition| fade.opacity.clone());
15238            opacity.value(&tester.cell.borrow())
15239        }
15240
15241        /// The colour of the `IconTheme` nearest the `Icon` showing `icon`: Dart's
15242        /// `tester.widget<IconTheme>(find.widgetWithIcon(IconTheme, icon).first).data.color`.
15243        fn icon_theme_color(tester: &WidgetTester, icon: &IconData) -> Option<Color> {
15244            let found = tester.element(find::by_icon(icon));
15245            let icon_theme = tester
15246                .ancestors(found)
15247                .into_iter()
15248                .find(|element| {
15249                    let app = tester.cell.borrow();
15250                    waft_widgets::downcast_widget::<IconTheme>(&**element.widget(&app)).is_some()
15251                })
15252                .expect("an IconTheme above the icon");
15253            tester.widget(icon_theme, |theme: &IconTheme| {
15254                theme.data.color.as_ref().map(|color| color.color())
15255            })
15256        }
15257
15258        /// Dart's `tester.getSize(find.byIcon(icon))`.
15259        fn icon_size(tester: &WidgetTester, icon: &IconData) -> Size {
15260            tester.get_size(find::by_icon(icon))
15261        }
15262
15263        /// Dart's `getIconStyle(tester, icon)?.color`.
15264        fn icon_glyph_color(tester: &WidgetTester, icon: &IconData) -> Option<Color> {
15265            let found = tester.element(find::by_icon(icon));
15266            style_color(&tester.glyph_style(found))
15267        }
15268
15269        fn outline(color: Color, width: f64) -> OutlineInputBorder {
15270            OutlineInputBorder::new().border_side(BorderSide {
15271                color,
15272                width,
15273                ..BorderSide::default()
15274            })
15275        }
15276
15277        fn border_is(tester: &WidgetTester, expected: &dyn ShapeBorder) -> bool {
15278            get_border(tester).expect("a border").eq_shape(expected)
15279        }
15280
15281        fn constraints(
15282            min_width: f64,
15283            max_width: f64,
15284            min_height: f64,
15285            max_height: f64,
15286        ) -> BoxConstraints {
15287            BoxConstraints {
15288                min_width,
15289                max_width,
15290                min_height,
15291                max_height,
15292            }
15293        }
15294
15295        fn decorator_render(tester: &WidgetTester) -> waft_rendering::AnyRenderBox {
15296            tester
15297                .render_object(find::by_type::<InputDecorator>())
15298                .as_box()
15299                .expect("a render box")
15300        }
15301
15302        fn key_size(tester: &WidgetTester, key: &GlobalKey) -> Size {
15303            let render = tester.render_object(key).as_box().expect("a render box");
15304            render.size(&tester.cell.borrow())
15305        }
15306
15307        fn pump(tester: &mut WidgetTester, decorator: BuildInputDecorator) {
15308            tester.pump_widget(decorator.build());
15309        }
15310
15311        // input_decorator_test.dart 'InputDecorationThemeData.inputDecoration with WidgetState'.
15312        #[test]
15313        fn widget_state_values_go_from_the_theme_to_the_decoration_unless_it_has_its_own() {
15314            test_widgets(|_tester| {
15315                let theme_style: AnyTextStyle =
15316                    WidgetStateTextStyle::resolve_with(|_states: &WidgetStates| {
15317                        TextStyle::new().color(Colors::GREEN.primary())
15318                    })
15319                    .into_any();
15320                let decoration_style: AnyTextStyle =
15321                    WidgetStateTextStyle::resolve_with(|_states: &WidgetStates| {
15322                        TextStyle::new().color(Colors::BLUE.primary())
15323                    })
15324                    .into_any();
15325                let none = InputBorderRef::none();
15326
15327                // InputDecorationThemeData arguments define InputDecoration properties.
15328                let decoration = InputDecoration::new().apply_defaults(
15329                    InputDecorationThemeData::new()
15330                        .label_style(theme_style.clone())
15331                        .helper_style(theme_style.clone())
15332                        .hint_style(theme_style.clone())
15333                        .error_style(theme_style.clone())
15334                        .is_dense(true)
15335                        .content_padding(EdgeInsets::all(1.0))
15336                        .prefix_style(theme_style.clone())
15337                        .suffix_style(theme_style.clone())
15338                        .counter_style(theme_style.clone())
15339                        .filled(true)
15340                        .fill_color(Colors::RED.primary())
15341                        .focus_color(Colors::BLUE.primary())
15342                        .border(InputBorderRef::none())
15343                        .align_label_with_hint(true)
15344                        .constraints(constraints(10.0, 20.0, 30.0, 40.0)),
15345                );
15346
15347                assert_eq!(decoration.label_style, Some(theme_style.clone()));
15348                assert_eq!(decoration.helper_style, Some(theme_style.clone()));
15349                assert_eq!(decoration.hint_style, Some(theme_style.clone()));
15350                assert_eq!(decoration.error_style, Some(theme_style.clone()));
15351                assert_eq!(decoration.is_dense, Some(true));
15352                assert_eq!(
15353                    decoration.content_padding,
15354                    Some(EdgeInsets::all(1.0).into())
15355                );
15356                assert_eq!(decoration.prefix_style, Some(theme_style.clone()));
15357                assert_eq!(decoration.suffix_style, Some(theme_style.clone()));
15358                assert_eq!(decoration.counter_style, Some(theme_style.clone()));
15359                assert_eq!(decoration.filled, Some(true));
15360                assert_eq!(
15361                    decoration.fill_color,
15362                    Some(AnyColor::from(Colors::RED.primary()))
15363                );
15364                assert!(decoration.border.as_deref() == Some(&*none));
15365                assert_eq!(decoration.align_label_with_hint, Some(true));
15366                assert_eq!(
15367                    decoration.constraints,
15368                    Some(constraints(10.0, 20.0, 30.0, 40.0))
15369                );
15370
15371                // InputDecoration (baseDecoration) defines InputDecoration properties
15372                let border = WidgetStateInputBorder::resolve_with(|_states: &WidgetStates| {
15373                    InputBorderRef::new(OutlineInputBorder::new())
15374                });
15375                let decoration = InputDecoration::new()
15376                    .label_style(decoration_style.clone())
15377                    .helper_style(decoration_style.clone())
15378                    .hint_style(decoration_style.clone())
15379                    .error_style(decoration_style.clone())
15380                    .is_dense(false)
15381                    .content_padding(EdgeInsets::all(4.0))
15382                    .prefix_style(decoration_style.clone())
15383                    .suffix_style(decoration_style.clone())
15384                    .counter_style(decoration_style.clone())
15385                    .filled(false)
15386                    .fill_color(Colors::BLUE.primary())
15387                    .border(border)
15388                    .align_label_with_hint(false)
15389                    .constraints(constraints(10.0, 20.0, 30.0, 40.0))
15390                    .apply_defaults(
15391                        InputDecorationThemeData::new()
15392                            .label_style(theme_style.clone())
15393                            .helper_style(theme_style.clone())
15394                            .helper_max_lines(5)
15395                            .hint_style(theme_style.clone())
15396                            .error_style(theme_style.clone())
15397                            .error_max_lines(4)
15398                            .is_dense(true)
15399                            .content_padding(EdgeInsets::all(1.0))
15400                            .prefix_style(theme_style.clone())
15401                            .suffix_style(theme_style.clone())
15402                            .counter_style(theme_style.clone())
15403                            .filled(true)
15404                            .fill_color(Colors::RED.primary())
15405                            .focus_color(Colors::BLUE.primary())
15406                            .border(InputBorderRef::none())
15407                            .align_label_with_hint(true)
15408                            .constraints(constraints(40.0, 30.0, 20.0, 10.0)),
15409                    );
15410
15411                assert_eq!(decoration.label_style, Some(decoration_style.clone()));
15412                assert_eq!(decoration.helper_style, Some(decoration_style.clone()));
15413                assert_eq!(decoration.helper_max_lines, Some(5));
15414                assert_eq!(decoration.hint_style, Some(decoration_style.clone()));
15415                assert_eq!(decoration.error_style, Some(decoration_style.clone()));
15416                assert_eq!(decoration.error_max_lines, Some(4));
15417                assert_eq!(decoration.is_dense, Some(false));
15418                assert_eq!(
15419                    decoration.content_padding,
15420                    Some(EdgeInsets::all(4.0).into())
15421                );
15422                assert_eq!(decoration.prefix_style, Some(decoration_style.clone()));
15423                assert_eq!(decoration.suffix_style, Some(decoration_style.clone()));
15424                assert_eq!(decoration.counter_style, Some(decoration_style.clone()));
15425                assert_eq!(decoration.filled, Some(false));
15426                assert_eq!(
15427                    decoration.fill_color,
15428                    Some(AnyColor::from(Colors::BLUE.primary()))
15429                );
15430                assert!(
15431                    decoration
15432                        .border
15433                        .as_ref()
15434                        .expect("a border")
15435                        .as_any()
15436                        .is::<WidgetStateInputBorder>()
15437                );
15438                assert_eq!(decoration.align_label_with_hint, Some(false));
15439                assert_eq!(
15440                    decoration.constraints,
15441                    Some(constraints(10.0, 20.0, 30.0, 40.0))
15442                );
15443            });
15444        }
15445
15446        // input_decorator_test.dart 'InputDecoration with WidgetStateInputBorder', on an
15447        // `InputDecorator` whose `isFocused`/`isHovering` stand for the `TextField`'s focus and the
15448        // mouse over it.
15449        #[test]
15450        fn a_widget_state_input_border_paints_the_border_of_the_state() {
15451            test_widgets(|tester| {
15452                let outline_input_border = || {
15453                    WidgetStateInputBorder::from_map(vec![
15454                        (
15455                            WidgetState::Focused.into(),
15456                            InputBorderRef::new(outline(Colors::BLUE.primary(), 4.0)),
15457                        ),
15458                        (
15459                            WidgetState::Hovered.into(),
15460                            InputBorderRef::new(outline(Colors::CYAN.primary(), 8.0)),
15461                        ),
15462                        (
15463                            WidgetState::any(),
15464                            InputBorderRef::new(OutlineInputBorder::new()),
15465                        ),
15466                    ])
15467                };
15468                let build = |is_focused: bool, is_hovering: bool| {
15469                    BuildInputDecorator::new(InputDecoration::new().border(outline_input_border()))
15470                        .is_focused(is_focused)
15471                        .is_hovering(is_hovering)
15472                        .build()
15473                };
15474                tester.pump_widget(build(false, false));
15475                assert_paints(
15476                    &border_painter_ops(tester),
15477                    &[PaintCall::RRect {
15478                        rrect: None,
15479                        color: None,
15480                        style: Some(PaintedStyle::Stroke(Some(1.0))),
15481                        has_mask_filter: None,
15482                    }],
15483                );
15484
15485                tester.pump_widget(build(true, false));
15486                tester.pump_and_settle();
15487                assert_paints(
15488                    &border_painter_ops(tester),
15489                    &[PaintCall::RRect {
15490                        rrect: None,
15491                        color: Some(Colors::BLUE.primary()),
15492                        style: Some(PaintedStyle::Stroke(Some(4.0))),
15493                        has_mask_filter: None,
15494                    }],
15495                );
15496
15497                tester.pump_widget(build(false, true));
15498                tester.pump_and_settle();
15499                // The 8-wide side deflates the 4-radius corners to nothing, so valo records the
15500                // stroked rrect as a plain path where Dart's `drawRRect` stays an rrect call.
15501                assert_paints(
15502                    &border_painter_ops(tester),
15503                    &[PaintCall::Path {
15504                        color: Some(Colors::CYAN.primary()),
15505                        style: Some(PaintedStyle::Stroke(Some(8.0))),
15506                        includes: Vec::new(),
15507                        excludes: Vec::new(),
15508                    }],
15509                );
15510            });
15511        }
15512
15513        // input_decorator_test.dart 'InputDecorator constrained to 0x0'.
15514        #[test]
15515        fn a_decorator_constrained_to_zero_by_zero_lays_out() {
15516            test_widgets(|tester| {
15517                tester.pump_widget(
15518                    crate::material::Material::new()
15519                        .child(Directionality::new(
15520                            TextDirection::Ltr,
15521                            UnconstrainedBox::new().child(
15522                                ConstrainedBox::new(BoxConstraints::tight(Size::ZERO)).child(
15523                                    InputDecorator::new(
15524                                        InputDecoration::new()
15525                                            .label_text("XP")
15526                                            .border(OutlineInputBorder::new()),
15527                                    ),
15528                                ),
15529                            ),
15530                        ))
15531                        .into_widget(),
15532                );
15533            });
15534        }
15535
15536        fn labeled_input_decorator(show_fix: bool, is_focused: bool) -> WidgetRef {
15537            const PREFIX_TEXT: &str = "The five boxing wizards jump quickly.";
15538            const SUFFIX_TEXT: &str = "Suffix";
15539            let mut decoration = InputDecoration::new()
15540                .icon(icon(Icons::assistant()))
15541                .suffix_icon(icon(Icons::threesixty()))
15542                .label_text("My Label");
15543            if show_fix {
15544                decoration = decoration.prefix_text(PREFIX_TEXT).suffix_text(SUFFIX_TEXT);
15545            }
15546            MaterialApp::new()
15547                .home(Material::new().child(Builder::new(move |app, context| {
15548                    Theme::new(
15549                        Theme::of(app, context),
15550                        waft_widgets::Align::new()
15551                            .alignment(AlignmentGeometry::Alignment(
15552                                waft_painting::Alignment::TOP_LEFT,
15553                            ))
15554                            .child(
15555                                InputDecorator::new(decoration.clone())
15556                                    .is_empty(true)
15557                                    .is_focused(is_focused)
15558                                    .child(input_text()),
15559                            ),
15560                    )
15561                    .into_widget()
15562                })))
15563                .into_widget()
15564        }
15565
15566        fn text_size(tester: &WidgetTester, text: &str) -> Size {
15567            tester.get_size(find::text(text))
15568        }
15569
15570        // input_decorator_test.dart "InputDecorator label width isn't affected by prefix or
15571        // suffix", on an empty `InputDecorator` that the tap focuses.
15572        #[test]
15573        fn the_label_width_is_not_affected_by_the_prefix_or_suffix() {
15574            test_widgets(|tester| {
15575                const PREFIX_TEXT: &str = "The five boxing wizards jump quickly.";
15576                const SUFFIX_TEXT: &str = "Suffix";
15577                // Build with no prefix or suffix.
15578                tester.pump_widget(labeled_input_decorator(false, false));
15579
15580                // Get the width of the label when there is no prefix/suffix.
15581                expect(tester, &find::text(PREFIX_TEXT), finds_nothing());
15582                expect(tester, &find::text(SUFFIX_TEXT), finds_nothing());
15583                let label_width = text_size(tester, "My Label").width();
15584
15585                // Build with a prefix and suffix.
15586                tester.pump_widget(labeled_input_decorator(true, false));
15587
15588                // The prefix and suffix exist but aren't visible. They have not affected
15589                // the width of the label.
15590                expect(tester, &find::text(PREFIX_TEXT), finds_one_widget());
15591                assert_eq!(get_opacity(tester, PREFIX_TEXT), 0.0);
15592                expect(tester, &find::text(SUFFIX_TEXT), finds_one_widget());
15593                assert_eq!(get_opacity(tester, SUFFIX_TEXT), 0.0);
15594                assert_eq!(text_size(tester, "My Label").width(), label_width);
15595
15596                // Tap to focus.
15597                tester.pump_widget(labeled_input_decorator(true, true));
15598                tester.pump_and_settle();
15599
15600                // The prefix and suffix are visible, and the label is floating and still
15601                // hasn't had its width affected.
15602                assert_eq!(text_size(tester, "My Label").width(), label_width);
15603                assert_eq!(get_opacity(tester, PREFIX_TEXT), 1.0);
15604            });
15605        }
15606
15607        // input_decorator_test.dart 'Prefix and suffix are not visible when decorator is empty'.
15608        #[test]
15609        fn the_prefix_and_suffix_are_hidden_when_the_decorator_is_empty() {
15610            test_widgets(|tester| {
15611                pump(
15612                    tester,
15613                    BuildInputDecorator::new(
15614                        InputDecoration::new()
15615                            .filled(true)
15616                            .label_text(LABEL_TEXT)
15617                            .prefix_text("Prefix")
15618                            .suffix_text("Suffix"),
15619                    )
15620                    .is_empty(true),
15621                );
15622
15623                // Prefix and suffix are hidden.
15624                assert_eq!(get_opacity(tester, "Prefix"), 0.0);
15625                assert_eq!(get_opacity(tester, "Suffix"), 0.0);
15626            });
15627        }
15628
15629        // input_decorator_test.dart 'Prefix and suffix are visible when decorator is empty and
15630        // floating behavior is FloatingBehavior.always'.
15631        #[test]
15632        fn the_prefix_and_suffix_show_when_the_decorator_is_empty_and_the_label_always_floats() {
15633            test_widgets(|tester| {
15634                pump(
15635                    tester,
15636                    BuildInputDecorator::new(
15637                        InputDecoration::new()
15638                            .filled(true)
15639                            .label_text(LABEL_TEXT)
15640                            .prefix_text("Prefix")
15641                            .suffix_text("Suffix")
15642                            .floating_label_behavior(FloatingLabelBehavior::Always),
15643                    )
15644                    .is_empty(true),
15645                );
15646
15647                // Prefix and suffix are visible.
15648                assert_eq!(get_opacity(tester, "Prefix"), 1.0);
15649                assert_eq!(get_opacity(tester, "Suffix"), 1.0);
15650            });
15651        }
15652
15653        fn long_labeled_input_decorator(
15654            floating_label_behavior: FloatingLabelBehavior,
15655            is_focused: bool,
15656        ) -> WidgetRef {
15657            const LONG_LABEL: &str = "Flutter is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase.";
15658            MaterialApp::new()
15659                .home(
15660                    Scaffold::new().body(
15661                        SizedBox::new().width(300.0).child(
15662                            InputDecorator::new(
15663                                InputDecoration::new()
15664                                    .border(OutlineInputBorder::new().border_side(BorderSide {
15665                                        color: Colors::GREEN_ACCENT.primary(),
15666                                        ..BorderSide::default()
15667                                    }))
15668                                    .suffix_icon(icon(Icons::arrow_drop_down()))
15669                                    .floating_label_behavior(floating_label_behavior)
15670                                    .label_text(LONG_LABEL),
15671                            )
15672                            .is_empty(true)
15673                            .is_focused(is_focused)
15674                            .child(input_text()),
15675                        ),
15676                    ),
15677                )
15678                .into_widget()
15679        }
15680
15681        // input_decorator_test.dart 'OutlineInputBorder and InputDecorator long labels and in
15682        // Floating, the width should ignore the icon width', on an empty `InputDecorator` that the
15683        // tap focuses.
15684        #[test]
15685        fn a_long_floating_outlined_label_is_wider_than_its_inline_width() {
15686            test_widgets(|tester| {
15687                tester.pump_widget(long_labeled_input_decorator(
15688                    FloatingLabelBehavior::Never,
15689                    false,
15690                ));
15691
15692                let label_width = get_label_rect(tester).width();
15693
15694                tester.pump_widget(long_labeled_input_decorator(
15695                    FloatingLabelBehavior::Always,
15696                    false,
15697                ));
15698                tester.pump_by(K_TRANSITION_DURATION);
15699
15700                let floated_label_width = get_label_rect(tester).width();
15701
15702                assert!(floated_label_width > label_width);
15703
15704                tester.pump_widget(long_labeled_input_decorator(
15705                    FloatingLabelBehavior::Auto,
15706                    false,
15707                ));
15708                tester.pump_by(K_TRANSITION_DURATION);
15709
15710                assert_eq!(get_label_rect(tester).width(), label_width);
15711
15712                // Click for Focus.
15713                tester.pump_widget(long_labeled_input_decorator(
15714                    FloatingLabelBehavior::Auto,
15715                    true,
15716                ));
15717                // Default animation duration is 167ms.
15718                tester.pump_by(Duration::from_millis(80));
15719
15720                assert!(get_label_rect(tester).width() > label_width);
15721                assert!(get_label_rect(tester).width() <= floated_label_width);
15722
15723                tester.pump_by(K_TRANSITION_DURATION);
15724
15725                assert_eq!(get_label_rect(tester).width(), floated_label_width);
15726            });
15727        }
15728
15729        fn density_row(
15730            visual_density: VisualDensity,
15731            unconstrained: &GlobalKey,
15732            constrained: &GlobalKey,
15733        ) -> WidgetRef {
15734            let unconstrained = unconstrained.clone();
15735            let constrained = constrained.clone();
15736            MaterialApp::new()
15737                .home(Material::new().child(Builder::new(move |app, context| {
15738                    Theme::new(
15739                        Theme::of(app, context)
15740                            .copy_with()
15741                            .visual_density(visual_density)
15742                            .build(),
15743                        Center::new().child(
15744                            Row::new().children([
15745                                SizedBox::new()
15746                                    .width(35.0)
15747                                    .child(
15748                                        crate::TextField::new().key(unconstrained.clone().into()),
15749                                    )
15750                                    .into_widget(),
15751                                SizedBox::new()
15752                                    .width(35.0)
15753                                    // 48 is the height that this TextField would take when
15754                                    // laid out with no constraints.
15755                                    .height(48.0)
15756                                    .child(crate::TextField::new().key(constrained.clone().into()))
15757                                    .into_widget(),
15758                            ]),
15759                        ),
15760                    )
15761                    .into_widget()
15762                })))
15763                .into_widget()
15764        }
15765
15766        // input_decorator_test.dart 'given enough space, constrained and unconstrained heights
15767        // result in the same size widget'.
15768        #[test]
15769        fn constrained_and_unconstrained_heights_give_the_same_size_given_enough_space() {
15770            test_widgets(|tester| {
15771                let key_unconstrained = GlobalKey::new();
15772                let key_constrained = GlobalKey::new();
15773                tester.pump_widget(density_row(
15774                    VisualDensity::STANDARD,
15775                    &key_unconstrained,
15776                    &key_constrained,
15777                ));
15778                let constrained_height = key_size(tester, &key_constrained).height();
15779                let unconstrained_height = key_size(tester, &key_unconstrained).height();
15780                assert_eq!(constrained_height, unconstrained_height);
15781
15782                tester.pump_widget(density_row(
15783                    VisualDensity::COMPACT,
15784                    &key_unconstrained,
15785                    &key_constrained,
15786                ));
15787                let constrained_height_compact = key_size(tester, &key_constrained).height();
15788                let unconstrained_height_compact = key_size(tester, &key_unconstrained).height();
15789                assert_eq!(constrained_height_compact, unconstrained_height_compact);
15790            });
15791        }
15792
15793        // input_decorator_test.dart 'A vertically constrained TextField still positions its text
15794        // inside of itself', on an `InputDecorator` around the `TextField`'s input.
15795        #[test]
15796        fn a_vertically_constrained_decorator_positions_its_text_inside_itself() {
15797            test_widgets(|tester| {
15798                tester.pump_widget(
15799                    MaterialApp::new()
15800                        .home(
15801                            Material::new().child(
15802                                Center::new().child(
15803                                    SizedBox::new().width(200.0).height(28.0).child(
15804                                        InputDecorator::new(InputDecoration::new()).child(
15805                                            Text::new("A").style(
15806                                                TextStyle::new().font_size(16.0).height(1.5),
15807                                            ),
15808                                        ),
15809                                    ),
15810                                ),
15811                            ),
15812                        )
15813                        .into_widget(),
15814                );
15815
15816                let field = get_decorator_rect(tester);
15817                let text = tester.get_rect(find::text("A"));
15818
15819                // The text is inside the field.
15820                assert!(text.height() < field.bottom - field.top);
15821                assert!(text.top > field.top);
15822                assert!(text.top < field.bottom);
15823            });
15824        }
15825
15826        // input_decorator_test.dart 'Visual density is included in the intrinsic height
15827        // calculation', on `InputDecorator`s around the `TextField`'s input.
15828        #[test]
15829        fn the_visual_density_is_included_in_the_intrinsic_height() {
15830            test_widgets(|tester| {
15831                let key = GlobalKey::new();
15832                let intrinsic_height_key = GlobalKey::new();
15833                let (k1, k2) = (key.clone(), intrinsic_height_key.clone());
15834                tester.pump_widget(
15835                    MaterialApp::new()
15836                        .home(Material::new().child(Builder::new(move |app, context| {
15837                            Theme::new(
15838                                Theme::of(app, context)
15839                                    .copy_with()
15840                                    .visual_density(VisualDensity::COMPACT)
15841                                    .build(),
15842                                Center::new().child(
15843                                    Row::new().children([
15844                                        SizedBox::new()
15845                                            .width(35.0)
15846                                            .child(
15847                                                InputDecorator::new(InputDecoration::new())
15848                                                    .key(k1.clone().into())
15849                                                    .child(input_text()),
15850                                            )
15851                                            .into_widget(),
15852                                        SizedBox::new()
15853                                            .width(35.0)
15854                                            .child(
15855                                                IntrinsicHeight::new().child(
15856                                                    InputDecorator::new(InputDecoration::new())
15857                                                        .key(k2.clone().into())
15858                                                        .child(input_text()),
15859                                                ),
15860                                            )
15861                                            .into_widget(),
15862                                    ]),
15863                                ),
15864                            )
15865                            .into_widget()
15866                        })))
15867                        .into_widget(),
15868                );
15869
15870                let height = key_size(tester, &key).height();
15871                let intrinsic_height = key_size(tester, &intrinsic_height_key).height();
15872                assert_eq!(intrinsic_height, height);
15873            });
15874        }
15875
15876        /// Dart's `SizedBox(width:, child: IntrinsicHeight(child: Column(children:
15877        /// [TextField(decoration:)])))` under `Center` in a `Material` app, on an
15878        /// `InputDecorator` around the `TextField`'s input.
15879        fn pump_intrinsic_column(
15880            tester: &mut WidgetTester,
15881            width: Option<f64>,
15882            decoration: InputDecoration,
15883        ) {
15884            let column = IntrinsicHeight::new().child(
15885                Column::new().children([InputDecorator::new(decoration)
15886                    .child(input_text())
15887                    .into_widget()]),
15888            );
15889            let body = match width {
15890                Some(width) => SizedBox::new().width(width).child(column).into_widget(),
15891                None => column.into_widget(),
15892            };
15893            tester.pump_widget(
15894                MaterialApp::new()
15895                    .home(Material::new().child(Center::new().child(body)))
15896                    .into_widget(),
15897            );
15898        }
15899
15900        // input_decorator_test.dart 'Min intrinsic height for TextField with no content padding'.
15901        #[test]
15902        fn the_min_intrinsic_height_lays_out_with_no_content_padding() {
15903            test_widgets(|tester| {
15904                pump_intrinsic_column(
15905                    tester,
15906                    None,
15907                    InputDecoration::new()
15908                        .label_text("Label Text")
15909                        .helper_text("Helper Text")
15910                        .content_padding(EdgeInsets::ZERO),
15911                );
15912            });
15913        }
15914
15915        // input_decorator_test.dart 'Min intrinsic height for TextField with prefix icon'.
15916        #[test]
15917        fn the_min_intrinsic_height_lays_out_with_a_prefix_icon() {
15918            test_widgets(|tester| {
15919                pump_intrinsic_column(
15920                    tester,
15921                    Some(100.0),
15922                    InputDecoration::new().prefix_icon(icon(Icons::search())),
15923                );
15924            });
15925        }
15926
15927        // input_decorator_test.dart 'Min intrinsic height for TextField with suffix icon'.
15928        #[test]
15929        fn the_min_intrinsic_height_lays_out_with_a_suffix_icon() {
15930            test_widgets(|tester| {
15931                pump_intrinsic_column(
15932                    tester,
15933                    Some(100.0),
15934                    InputDecoration::new().suffix_icon(icon(Icons::search())),
15935                );
15936            });
15937        }
15938
15939        // input_decorator_test.dart 'Min intrinsic height for TextField with prefix'.
15940        #[test]
15941        fn the_min_intrinsic_height_lays_out_with_a_prefix() {
15942            test_widgets(|tester| {
15943                pump_intrinsic_column(
15944                    tester,
15945                    Some(100.0),
15946                    InputDecoration::new().prefix(Text::new("prefix")),
15947                );
15948            });
15949        }
15950
15951        // input_decorator_test.dart 'Min intrinsic height for TextField with suffix'.
15952        #[test]
15953        fn the_min_intrinsic_height_lays_out_with_a_suffix() {
15954            test_widgets(|tester| {
15955                pump_intrinsic_column(
15956                    tester,
15957                    Some(100.0),
15958                    InputDecoration::new().suffix(Text::new("suffix")),
15959                );
15960            });
15961        }
15962
15963        // input_decorator_test.dart 'Min intrinsic height for TextField with icon'.
15964        #[test]
15965        fn the_min_intrinsic_height_lays_out_with_an_icon() {
15966            test_widgets(|tester| {
15967                pump_intrinsic_column(
15968                    tester,
15969                    Some(100.0),
15970                    InputDecoration::new().icon(icon(Icons::search())),
15971                );
15972            });
15973        }
15974
15975        fn helper_decoration(width: f64) -> WidgetRef {
15976            MaterialApp::new()
15977                .home(
15978                    Scaffold::new().body(
15979                        SizedBox::new().width(width).child(
15980                            IntrinsicHeight::new().child(InputDecorator::new(
15981                                InputDecoration::new()
15982                                    .filled(true)
15983                                    .label_text(LABEL_TEXT)
15984                                    .helper_text("0123456789")
15985                                    .helper_max_lines(2),
15986                            )),
15987                        ),
15988                    ),
15989                )
15990                .into_widget()
15991        }
15992
15993        // input_decorator_test.dart 'Min intrinsic height calculation should not impact the
15994        // container height'.
15995        #[test]
15996        fn the_min_intrinsic_height_does_not_change_the_container_height() {
15997            test_widgets(|tester| {
15998                // Build once with enough width for the helper to fit in one line.
15999                tester.pump_widget(helper_decoration(300.0));
16000                let default_container_height = get_container_rect(tester).height();
16001
16002                // Build once with a smaller width that will force the helper text to wrap.
16003                tester.pump_widget(helper_decoration(150.0));
16004
16005                // The container height should be the same as before.
16006                assert_eq!(
16007                    get_container_rect(tester).height(),
16008                    default_container_height
16009                );
16010            });
16011        }
16012
16013        /// The four decorations of Dart's 'Min intrinsic height matches the laid out height'
16014        /// group, with `hintText`.
16015        fn intrinsic_decoration(name: &str) -> InputDecoration {
16016            match name {
16017                "isDense and isCollapsed" => InputDecoration::new()
16018                    .is_dense(true)
16019                    .is_collapsed(true)
16020                    .content_padding(EdgeInsets::ZERO)
16021                    .border(InputBorderRef::none())
16022                    .hint_text(HINT_TEXT),
16023                "isDense with zero content padding" => InputDecoration::new()
16024                    .is_dense(true)
16025                    .content_padding(EdgeInsets::ZERO)
16026                    .hint_text(HINT_TEXT),
16027                "isCollapsed" => InputDecoration::new()
16028                    .is_collapsed(true)
16029                    .hint_text(HINT_TEXT),
16030                "InputDecoration.collapsed" => {
16031                    InputDecoration::collapsed(None).hint_text(HINT_TEXT)
16032                }
16033                _ => unreachable!("one of the group's decorations"),
16034            }
16035        }
16036
16037        /// One case of Dart's 'Min intrinsic height matches the laid out height' group, on an
16038        /// empty `InputDecorator` around the `TextField`'s input.
16039        fn check_min_intrinsic_height_matches(
16040            tester: &mut WidgetTester,
16041            name: &str,
16042            visual_density: VisualDensity,
16043        ) {
16044            let decoration = intrinsic_decoration(name);
16045            let theme = ThemeData::builder()
16046                .visual_density(visual_density)
16047                .build(&tester.cell.borrow());
16048            tester.pump_widget(crate::test_support::material_app(
16049                theme,
16050                crate::material::Material::new()
16051                    .child(
16052                        Center::new().child(
16053                            SizedBox::new().width(200.0).child(
16054                                InputDecorator::new(decoration)
16055                                    .is_empty(true)
16056                                    .child(input_text()),
16057                            ),
16058                        ),
16059                    )
16060                    .into_widget(),
16061            ));
16062
16063            let decorator = decorator_render(tester);
16064            let mut app = tester.cell.borrow_mut();
16065            let height = decorator.size(&app).height();
16066            assert_eq!(decorator.get_min_intrinsic_height(&mut app, 200.0), height);
16067            assert_eq!(decorator.get_max_intrinsic_height(&mut app, 200.0), height);
16068        }
16069
16070        // input_decorator_test.dart 'Min intrinsic height matches the laid out height - isDense
16071        // and isCollapsed with standard visual density'.
16072        #[test]
16073        fn the_min_intrinsic_height_matches_the_layout_dense_and_collapsed_at_standard_density() {
16074            test_widgets(|tester| {
16075                check_min_intrinsic_height_matches(
16076                    tester,
16077                    "isDense and isCollapsed",
16078                    VisualDensity::STANDARD,
16079                )
16080            });
16081        }
16082
16083        // input_decorator_test.dart 'Min intrinsic height matches the laid out height - isDense
16084        // with zero content padding with standard visual density'.
16085        #[test]
16086        fn the_min_intrinsic_height_matches_the_layout_dense_without_padding_at_standard_density() {
16087            test_widgets(|tester| {
16088                check_min_intrinsic_height_matches(
16089                    tester,
16090                    "isDense with zero content padding",
16091                    VisualDensity::STANDARD,
16092                )
16093            });
16094        }
16095
16096        // input_decorator_test.dart 'Min intrinsic height matches the laid out height -
16097        // isCollapsed with standard visual density'.
16098        #[test]
16099        fn the_min_intrinsic_height_matches_the_layout_collapsed_at_standard_density() {
16100            test_widgets(|tester| {
16101                check_min_intrinsic_height_matches(tester, "isCollapsed", VisualDensity::STANDARD)
16102            });
16103        }
16104
16105        // input_decorator_test.dart 'Min intrinsic height matches the laid out height -
16106        // InputDecoration.collapsed with standard visual density'.
16107        #[test]
16108        fn the_min_intrinsic_height_matches_the_layout_of_a_collapsed_decoration_at_standard_density()
16109         {
16110            test_widgets(|tester| {
16111                check_min_intrinsic_height_matches(
16112                    tester,
16113                    "InputDecoration.collapsed",
16114                    VisualDensity::STANDARD,
16115                )
16116            });
16117        }
16118
16119        // input_decorator_test.dart 'Min intrinsic height matches the laid out height - isDense
16120        // and isCollapsed with compact visual density'.
16121        #[test]
16122        fn the_min_intrinsic_height_matches_the_layout_dense_and_collapsed_at_compact_density() {
16123            test_widgets(|tester| {
16124                check_min_intrinsic_height_matches(
16125                    tester,
16126                    "isDense and isCollapsed",
16127                    VisualDensity::COMPACT,
16128                )
16129            });
16130        }
16131
16132        // input_decorator_test.dart 'Min intrinsic height matches the laid out height - isDense
16133        // with zero content padding with compact visual density'.
16134        #[test]
16135        fn the_min_intrinsic_height_matches_the_layout_dense_without_padding_at_compact_density() {
16136            test_widgets(|tester| {
16137                check_min_intrinsic_height_matches(
16138                    tester,
16139                    "isDense with zero content padding",
16140                    VisualDensity::COMPACT,
16141                )
16142            });
16143        }
16144
16145        // input_decorator_test.dart 'Min intrinsic height matches the laid out height -
16146        // isCollapsed with compact visual density'.
16147        #[test]
16148        fn the_min_intrinsic_height_matches_the_layout_collapsed_at_compact_density() {
16149            test_widgets(|tester| {
16150                check_min_intrinsic_height_matches(tester, "isCollapsed", VisualDensity::COMPACT)
16151            });
16152        }
16153
16154        // input_decorator_test.dart 'Min intrinsic height matches the laid out height -
16155        // InputDecoration.collapsed with compact visual density'.
16156        #[test]
16157        fn the_min_intrinsic_height_matches_the_layout_of_a_collapsed_decoration_at_compact_density()
16158         {
16159            test_widgets(|tester| {
16160                check_min_intrinsic_height_matches(
16161                    tester,
16162                    "InputDecoration.collapsed",
16163                    VisualDensity::COMPACT,
16164                )
16165            });
16166        }
16167
16168        // input_decorator_test.dart 'Min intrinsic height matches the laid out height -
16169        // IntrinsicHeight does not overflow with a dense collapsed TextField', on an empty
16170        // `InputDecorator` around the `TextField`'s input.
16171        #[test]
16172        fn an_intrinsic_height_does_not_overflow_with_a_dense_collapsed_decorator() {
16173            test_widgets(|tester| {
16174                let theme = ThemeData::builder()
16175                    .visual_density(VisualDensity::COMPACT)
16176                    .build(&tester.cell.borrow());
16177                tester.pump_widget(crate::test_support::material_app(
16178                    theme,
16179                    Scaffold::new()
16180                        .body(
16181                            IntrinsicHeight::new().child(
16182                                Row::new()
16183                                    .cross_axis_alignment(CrossAxisAlignment::Stretch)
16184                                    .children([
16185                                        Expanded::new(
16186                                            Column::new()
16187                                                .main_axis_size(MainAxisSize::Min)
16188                                                .children([
16189                                                    Text::new("Text").into_widget(),
16190                                                    InputDecorator::new(
16191                                                        InputDecoration::new()
16192                                                            .is_dense(true)
16193                                                            .is_collapsed(true)
16194                                                            .content_padding(EdgeInsets::ZERO)
16195                                                            .border(InputBorderRef::none())
16196                                                            .hint_text(HINT_TEXT),
16197                                                    )
16198                                                    .is_empty(true)
16199                                                    .child(input_text())
16200                                                    .into_widget(),
16201                                                ]),
16202                                        )
16203                                        .into_widget(),
16204                                        Text::new("Right text").into_widget(),
16205                                    ]),
16206                            ),
16207                        )
16208                        .into_widget(),
16209                ));
16210            });
16211        }
16212
16213        fn intrinsic_padding() -> EdgeInsetsGeometry {
16214            EdgeInsetsDirectional::only(12.0, 0.0, 24.0, 0.0).into()
16215        }
16216
16217        /// Dart's `measureText`: the size of the input text in an intrinsic-width decorator.
16218        fn measure_text(
16219            tester: &mut WidgetTester,
16220            decoration: InputDecoration,
16221            direction: TextDirection,
16222        ) -> Size {
16223            tester.pump_widget(
16224                BuildInputDecorator::new(decoration)
16225                    .use_intrinsic_width(true)
16226                    .text_direction(direction)
16227                    .build(),
16228            );
16229            tester.get_size(find::text(INPUT_TEXT))
16230        }
16231
16232        fn without_icons() -> InputDecoration {
16233            InputDecoration::new().content_padding(intrinsic_padding())
16234        }
16235
16236        fn with_prefix() -> InputDecoration {
16237            without_icons().prefix_icon(icon(Icons::search()))
16238        }
16239
16240        fn with_suffix() -> InputDecoration {
16241            without_icons().suffix_icon(icon(Icons::search()))
16242        }
16243
16244        fn with_affixes() -> InputDecoration {
16245            without_icons()
16246                .prefix_icon(icon(Icons::search()))
16247                .suffix_icon(icon(Icons::search()))
16248        }
16249
16250        // input_decorator_test.dart 'Intrinsic width - with prefixIcon in LTR'.
16251        #[test]
16252        fn the_intrinsic_width_keeps_the_text_width_with_a_prefix_icon_ltr() {
16253            test_widgets(|tester| {
16254                assert_eq!(
16255                    measure_text(tester, with_prefix(), TextDirection::Ltr).width(),
16256                    measure_text(tester, without_icons(), TextDirection::Ltr).width()
16257                );
16258            });
16259        }
16260
16261        // input_decorator_test.dart 'Intrinsic width - with suffixIcon in LTR'.
16262        #[test]
16263        fn the_intrinsic_width_keeps_the_text_width_with_a_suffix_icon_ltr() {
16264            test_widgets(|tester| {
16265                assert_eq!(
16266                    measure_text(tester, with_suffix(), TextDirection::Ltr).width(),
16267                    measure_text(tester, without_icons(), TextDirection::Ltr).width()
16268                );
16269            });
16270        }
16271
16272        // input_decorator_test.dart 'Intrinsic width - with prefixIcon and suffixIcon in LTR'.
16273        #[test]
16274        fn the_intrinsic_width_keeps_the_text_width_with_both_icons_ltr() {
16275            test_widgets(|tester| {
16276                assert_eq!(
16277                    measure_text(tester, with_affixes(), TextDirection::Ltr).width(),
16278                    measure_text(tester, without_icons(), TextDirection::Ltr).width()
16279                );
16280            });
16281        }
16282
16283        // input_decorator_test.dart 'Intrinsic width - with prefixIcon in RTL'.
16284        #[test]
16285        fn the_intrinsic_width_keeps_the_text_width_with_a_prefix_icon_rtl() {
16286            test_widgets(|tester| {
16287                assert_eq!(
16288                    measure_text(tester, with_prefix(), TextDirection::Rtl).width(),
16289                    measure_text(tester, without_icons(), TextDirection::Rtl).width()
16290                );
16291            });
16292        }
16293
16294        // input_decorator_test.dart 'Intrinsic width - with suffixIcon in RTL'.
16295        #[test]
16296        fn the_intrinsic_width_keeps_the_text_width_with_a_suffix_icon_rtl() {
16297            test_widgets(|tester| {
16298                assert_eq!(
16299                    measure_text(tester, with_suffix(), TextDirection::Rtl).width(),
16300                    measure_text(tester, without_icons(), TextDirection::Rtl).width()
16301                );
16302            });
16303        }
16304
16305        // input_decorator_test.dart 'Intrinsic width - with prefixIcon and suffixIcon in RTL'.
16306        #[test]
16307        fn the_intrinsic_width_keeps_the_text_width_with_both_icons_rtl() {
16308            test_widgets(|tester| {
16309                assert_eq!(
16310                    measure_text(tester, with_affixes(), TextDirection::Rtl).width(),
16311                    measure_text(tester, without_icons(), TextDirection::Rtl).width()
16312                );
16313            });
16314        }
16315
16316        fn intrinsic_width_of(
16317            tester: &mut WidgetTester,
16318            decoration: InputDecoration,
16319            is_empty: bool,
16320            child: WidgetRef,
16321        ) -> f64 {
16322            pump(
16323                tester,
16324                BuildInputDecorator::new(decoration)
16325                    .use_intrinsic_width(true)
16326                    .is_empty(is_empty)
16327                    .child(child),
16328            );
16329            get_decorator_rect(tester).width()
16330        }
16331
16332        fn sized_width(width: f64) -> WidgetRef {
16333            SizedBox::new().width(width).into_widget()
16334        }
16335
16336        // input_decorator_test.dart 'Intrinsic width - depends on hint width and content width
16337        // when decorator is empty'.
16338        #[test]
16339        fn the_intrinsic_width_of_an_empty_decorator_is_the_wider_of_hint_and_content() {
16340            test_widgets(|tester| {
16341                let decoration_with_hint = || {
16342                    InputDecoration::new()
16343                        .content_padding(EdgeInsets::ZERO)
16344                        .hint_text("Hint")
16345                };
16346                const HINT_TEXT_WIDTH: f64 = 66.0;
16347                const SMALL_CONTENT_WIDTH: f64 = 20.0;
16348                const LARGE_CONTENT_WIDTH: f64 = 80.0;
16349
16350                // Decorator width depends on the hint because the hint is larger than the content.
16351                assert_eq!(
16352                    intrinsic_width_of(
16353                        tester,
16354                        decoration_with_hint(),
16355                        true,
16356                        sized_width(SMALL_CONTENT_WIDTH)
16357                    ),
16358                    HINT_TEXT_WIDTH
16359                );
16360
16361                // Decorator width depends on the content because the content is larger than the hint.
16362                assert_eq!(
16363                    intrinsic_width_of(
16364                        tester,
16365                        decoration_with_hint(),
16366                        true,
16367                        sized_width(LARGE_CONTENT_WIDTH)
16368                    ),
16369                    LARGE_CONTENT_WIDTH
16370                );
16371            });
16372        }
16373
16374        // input_decorator_test.dart 'Intrinsic width - depends on content width when decorator is
16375        // not empty and maintainHintSize is false'.
16376        #[test]
16377        fn the_intrinsic_width_ignores_the_hint_when_not_empty_and_not_maintaining_its_size() {
16378            test_widgets(|tester| {
16379                let decoration_with_hint = InputDecoration::new()
16380                    .content_padding(EdgeInsets::ZERO)
16381                    .hint_text("Hint")
16382                    .maintain_hint_size(false);
16383                const CONTENT_WIDTH: f64 = 20.0;
16384
16385                // The hint width is ignored even if larger than the content width.
16386                assert_eq!(
16387                    intrinsic_width_of(
16388                        tester,
16389                        decoration_with_hint,
16390                        false,
16391                        sized_width(CONTENT_WIDTH)
16392                    ),
16393                    CONTENT_WIDTH
16394                );
16395            });
16396        }
16397
16398        // input_decorator_test.dart 'Intrinsic width - depends on hint width when decorator is not
16399        // empty and maintainHintSize is true'.
16400        #[test]
16401        fn the_intrinsic_width_keeps_the_hint_width_when_maintaining_its_size() {
16402            test_widgets(|tester| {
16403                let decoration_with_hint = InputDecoration::new()
16404                    .content_padding(EdgeInsets::ZERO)
16405                    .hint_text("Hint");
16406                const CONTENT_WIDTH: f64 = 20.0;
16407                const HINT_TEXT_WIDTH: f64 = 66.0;
16408                assert_eq!(
16409                    intrinsic_width_of(
16410                        tester,
16411                        decoration_with_hint,
16412                        false,
16413                        sized_width(CONTENT_WIDTH)
16414                    ),
16415                    HINT_TEXT_WIDTH
16416                );
16417            });
16418        }
16419
16420        fn decoration_with_label(maintain_label_size: bool) -> InputDecoration {
16421            InputDecoration::new()
16422                .content_padding(EdgeInsets::ZERO)
16423                .label(SizedBox::new().width(30.0))
16424                .maintain_label_size(maintain_label_size)
16425        }
16426
16427        // input_decorator_test.dart 'Intrinsic width - does not depend on label width when
16428        // decorator is empty and maintainLabelSize is false'.
16429        #[test]
16430        fn the_intrinsic_width_of_an_empty_decorator_ignores_the_label() {
16431            test_widgets(|tester| {
16432                // The label width is ignored even if larger than the content width.
16433                assert_eq!(
16434                    intrinsic_width_of(
16435                        tester,
16436                        decoration_with_label(false),
16437                        true,
16438                        SizedBox::shrink().into_widget()
16439                    ),
16440                    0.0
16441                );
16442            });
16443        }
16444
16445        // input_decorator_test.dart 'Intrinsic width - depends on label width when decorator is
16446        // empty and maintainLabelSize is true'.
16447        #[test]
16448        fn the_intrinsic_width_of_an_empty_decorator_keeps_the_label_when_maintaining_its_size() {
16449            test_widgets(|tester| {
16450                assert_eq!(
16451                    intrinsic_width_of(
16452                        tester,
16453                        decoration_with_label(true),
16454                        true,
16455                        SizedBox::shrink().into_widget()
16456                    ),
16457                    30.0
16458                );
16459            });
16460        }
16461
16462        // input_decorator_test.dart 'Intrinsic width - does not depend on label width when
16463        // decorator is not empty and maintainLabelSize is false'.
16464        #[test]
16465        fn the_intrinsic_width_ignores_the_label() {
16466            test_widgets(|tester| {
16467                // The label width is ignored even if larger than the content width.
16468                assert_eq!(
16469                    intrinsic_width_of(
16470                        tester,
16471                        decoration_with_label(false),
16472                        false,
16473                        sized_width(20.0)
16474                    ),
16475                    20.0
16476                );
16477            });
16478        }
16479
16480        // input_decorator_test.dart 'Intrinsic width - depends on label width when decorator is
16481        // not empty and maintainLabelSize is true'.
16482        #[test]
16483        fn the_intrinsic_width_keeps_the_label_when_maintaining_its_size() {
16484            test_widgets(|tester| {
16485                assert_eq!(
16486                    intrinsic_width_of(
16487                        tester,
16488                        decoration_with_label(true),
16489                        false,
16490                        sized_width(20.0)
16491                    ),
16492                    30.0
16493                );
16494            });
16495        }
16496
16497        // input_decorator_test.dart 'Ensure the height of labelStyle remains unchanged when
16498        // TextField is focused', on an empty `InputDecorator` that the focus request focuses.
16499        #[test]
16500        fn the_label_style_height_is_unchanged_when_focused() {
16501            test_widgets(|tester| {
16502                let build = |is_focused: bool| {
16503                    MaterialApp::new()
16504                        .home(
16505                            Material::new().child(
16506                                InputDecorator::new(InputDecoration::new().label_text("label"))
16507                                    .is_empty(true)
16508                                    .is_focused(is_focused)
16509                                    .child(input_text()),
16510                            ),
16511                        )
16512                        .into_widget()
16513                };
16514                tester.pump_widget(build(false));
16515                let before_style = get_label_style(tester);
16516                // Focused.
16517                tester.pump_widget(build(true));
16518                tester.pump_by(K_TRANSITION_DURATION);
16519
16520                assert_eq!(get_label_style(tester).height, before_style.height);
16521            });
16522        }
16523
16524        fn local(
16525            theme: InputDecorationThemeData,
16526            decoration: InputDecoration,
16527        ) -> BuildInputDecorator {
16528            BuildInputDecorator::new(decoration).local_input_decoration_theme(theme)
16529        }
16530
16531        fn indigo() -> Color {
16532            Colors::INDIGO.primary()
16533        }
16534
16535        fn indigo_style() -> TextStyle {
16536            TextStyle::new().color(indigo())
16537        }
16538
16539        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - labelStyle'.
16540        #[test]
16541        fn a_local_theme_label_style_overrides_the_default() {
16542            test_widgets(|tester| {
16543                pump(
16544                    tester,
16545                    local(
16546                        InputDecorationThemeData::new().label_style(indigo_style()),
16547                        InputDecoration::new().label_text(LABEL_TEXT),
16548                    ),
16549                );
16550                assert_eq!(style_color(&get_label_style(tester)), Some(indigo()));
16551            });
16552        }
16553
16554        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
16555        // floatingLabelStyle'.
16556        #[test]
16557        fn a_local_theme_floating_label_style_overrides_the_default() {
16558            test_widgets(|tester| {
16559                pump(
16560                    tester,
16561                    local(
16562                        InputDecorationThemeData::new().floating_label_style(indigo_style()),
16563                        InputDecoration::new().label_text(LABEL_TEXT),
16564                    )
16565                    .is_focused(true), // Label appears floating above input field.
16566                );
16567                assert_eq!(style_color(&get_label_style(tester)), Some(indigo()));
16568            });
16569        }
16570
16571        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - helperStyle'.
16572        #[test]
16573        fn a_local_theme_helper_style_overrides_the_default() {
16574            test_widgets(|tester| {
16575                pump(
16576                    tester,
16577                    local(
16578                        InputDecorationThemeData::new().helper_style(indigo_style()),
16579                        InputDecoration::new()
16580                            .label_text(LABEL_TEXT)
16581                            .helper_text(HELPER_TEXT),
16582                    ),
16583                );
16584                assert_eq!(
16585                    style_color(&rich_text_style(tester, HELPER_TEXT)),
16586                    Some(indigo())
16587                );
16588            });
16589        }
16590
16591        /// Dart's `tester.getRect(find.text(text))` of a `Text`.
16592        fn string_rect(tester: &WidgetTester, text: &str) -> waft_embedder::Rect {
16593            tester.get_rect(find::text(text))
16594        }
16595
16596        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
16597        // helperMaxLines'.
16598        #[test]
16599        fn a_local_theme_helper_max_lines_overrides_the_default() {
16600            test_widgets(|tester| {
16601                const HELPER_MAX_LINES: i32 = 2;
16602                pump(
16603                    tester,
16604                    local(
16605                        InputDecorationThemeData::new().helper_max_lines(HELPER_MAX_LINES),
16606                        InputDecoration::new()
16607                            .label_text(LABEL_TEXT)
16608                            .helper_text(THREE_LINES),
16609                    ),
16610                );
16611
16612                const HELPER_GAP: f64 = 4.0;
16613                const HELPER_HEIGHT: f64 = 16.0;
16614                const CONTAINER_HEIGHT: f64 = 56.0;
16615                let helper_rect = string_rect(tester, THREE_LINES);
16616                assert!(
16617                    (helper_rect.height() - HELPER_HEIGHT * f64::from(HELPER_MAX_LINES)).abs()
16618                        <= 0.25,
16619                    "{helper_rect:?}"
16620                );
16621                let height = get_decorator_rect(tester).height();
16622                assert!(
16623                    (height
16624                        - (CONTAINER_HEIGHT
16625                            + HELPER_GAP
16626                            + HELPER_HEIGHT * f64::from(HELPER_MAX_LINES)))
16627                    .abs()
16628                        <= 0.25,
16629                    "{height}"
16630                );
16631            });
16632        }
16633
16634        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - hintStyle'.
16635        #[test]
16636        fn a_local_theme_hint_style_overrides_the_default() {
16637            test_widgets(|tester| {
16638                pump(
16639                    tester,
16640                    local(
16641                        InputDecorationThemeData::new().hint_style(indigo_style()),
16642                        InputDecoration::new()
16643                            .label_text(LABEL_TEXT)
16644                            .hint_text(HINT_TEXT),
16645                    ),
16646                );
16647                assert_eq!(
16648                    style_color(&rich_text_style(tester, HINT_TEXT)),
16649                    Some(indigo())
16650                );
16651            });
16652        }
16653
16654        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
16655        // hintFadeDuration'.
16656        #[test]
16657        fn a_local_theme_hint_fade_duration_overrides_the_default() {
16658            test_widgets(|tester| {
16659                const HINT_FADE_DURATION: Duration = Duration::from_millis(404);
16660                let build = |is_empty: bool| {
16661                    local(
16662                        InputDecorationThemeData::new().hint_fade_duration(HINT_FADE_DURATION),
16663                        InputDecoration::new().hint_text(HINT_TEXT),
16664                    )
16665                    .is_empty(is_empty)
16666                    .build()
16667                };
16668
16669                // Build once with empty content.
16670                tester.pump_widget(build(true));
16671
16672                // Hint is visible (opacity 1.0).
16673                assert_eq!(get_opacity(tester, HINT_TEXT), 1.0);
16674
16675                // Rebuild with non-empty content.
16676                tester.pump_widget(build(false));
16677
16678                // The hint's opacity animates from 1.0 to 0.0.
16679                // The animation's default duration is 20ms.
16680                tester.pump_by(Duration::from_millis(200));
16681                let hint_opacity_200ms = get_opacity(tester, HINT_TEXT);
16682                assert!(hint_opacity_200ms > 0.0 && hint_opacity_200ms < 1.0);
16683                tester.pump_by(Duration::from_millis(200));
16684                let hint_opacity_400ms = get_opacity(tester, HINT_TEXT);
16685                assert!(hint_opacity_400ms > 0.0 && hint_opacity_400ms < hint_opacity_200ms);
16686                tester.pump_by(Duration::from_millis(4));
16687                assert_eq!(get_opacity(tester, HINT_TEXT), 0.0);
16688            });
16689        }
16690
16691        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - hintMaxLines'.
16692        #[test]
16693        fn a_local_theme_hint_max_lines_overrides_the_default() {
16694            test_widgets(|tester| {
16695                const HINT_MAX_LINES: i32 = 2;
16696                pump(
16697                    tester,
16698                    local(
16699                        InputDecorationThemeData::new().hint_max_lines(HINT_MAX_LINES),
16700                        InputDecoration::collapsed(Some(THREE_LINES.to_owned())),
16701                    ),
16702                );
16703
16704                const HINT_LINE_HEIGHT: f64 = 24.0; // Font size = 16 and font height = 1.5.
16705                assert_eq!(
16706                    get_decorator_rect(tester).size(),
16707                    Size::new(800.0, f64::from(HINT_MAX_LINES) * HINT_LINE_HEIGHT)
16708                );
16709            });
16710        }
16711
16712        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - errorStyle'.
16713        #[test]
16714        fn a_local_theme_error_style_overrides_the_default() {
16715            test_widgets(|tester| {
16716                pump(
16717                    tester,
16718                    local(
16719                        InputDecorationThemeData::new().error_style(indigo_style()),
16720                        InputDecoration::new()
16721                            .label_text(LABEL_TEXT)
16722                            .error_text(ERROR_TEXT),
16723                    )
16724                    .is_focused(true),
16725                );
16726                assert_eq!(
16727                    style_color(&rich_text_style(tester, ERROR_TEXT)),
16728                    Some(indigo())
16729                );
16730            });
16731        }
16732
16733        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
16734        // errorMaxLines'.
16735        #[test]
16736        fn a_local_theme_error_max_lines_overrides_the_default() {
16737            test_widgets(|tester| {
16738                const ERROR_MAX_LINES: i32 = 2;
16739                pump(
16740                    tester,
16741                    local(
16742                        InputDecorationThemeData::new().error_max_lines(ERROR_MAX_LINES),
16743                        InputDecoration::new()
16744                            .error_text(THREE_LINES)
16745                            .label_text("label")
16746                            .filled(true),
16747                    ),
16748                );
16749
16750                const HELPER_GAP: f64 = 4.0;
16751                const CONTAINER_HEIGHT: f64 = 56.0;
16752                const ERROR_HEIGHT: f64 = 16.0;
16753
16754                let error_rect = string_rect(tester, THREE_LINES);
16755                assert!(
16756                    (error_rect.height() - ERROR_HEIGHT * f64::from(ERROR_MAX_LINES)).abs() <= 0.25,
16757                    "{error_rect:?}"
16758                );
16759                let height = get_decorator_rect(tester).height();
16760                assert!(
16761                    (height
16762                        - (CONTAINER_HEIGHT
16763                            + HELPER_GAP
16764                            + ERROR_HEIGHT * f64::from(ERROR_MAX_LINES)))
16765                    .abs()
16766                        <= 0.25,
16767                    "{height}"
16768                );
16769            });
16770        }
16771
16772        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
16773        // floatingLabelBehavior'.
16774        #[test]
16775        fn a_local_theme_floating_label_behavior_overrides_the_default() {
16776            test_widgets(|tester| {
16777                pump(
16778                    tester,
16779                    local(
16780                        InputDecorationThemeData::new()
16781                            .floating_label_behavior(FloatingLabelBehavior::Never),
16782                        InputDecoration::new().label_text(LABEL_TEXT),
16783                    ),
16784                );
16785
16786                assert_eq!(get_decorator_rect(tester).size(), Size::new(800.0, 56.0));
16787                // Label line height is forced to 1.0 and font size is 16.0,
16788                // the label should be vertically centered (20 pixels above and below).
16789                assert_eq!(get_label_rect(tester).top, 20.0);
16790                assert_eq!(get_label_rect(tester).bottom, 36.0);
16791            });
16792        }
16793
16794        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
16795        // floatingLabelAlignment', through Dart's `buildInputDecoratorWithFloatingLabel`.
16796        #[test]
16797        fn a_local_theme_floating_label_alignment_overrides_the_default() {
16798            test_widgets(|tester| {
16799                pump(
16800                    tester,
16801                    BuildInputDecorator::new(
16802                        InputDecoration::new()
16803                            .content_padding(EdgeInsetsDirectional::only(40.0, 12.0, 0.0, 12.0))
16804                            .icon(icon(Icons::insert_link()))
16805                            .label_text(LABEL_TEXT)
16806                            .hint_text(HINT_TEXT)
16807                            .filled(true),
16808                    )
16809                    .local_input_decoration_theme(
16810                        InputDecorationThemeData::new()
16811                            .floating_label_alignment(FloatingLabelAlignment::CENTER),
16812                    ),
16813                );
16814                // icon (40) + (decorator (800) - icon (40)) / 2
16815                assert_eq!(get_label_rect(tester).center().dx(), 420.0);
16816            });
16817        }
16818
16819        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - isDense'.
16820        #[test]
16821        fn a_local_theme_is_dense_overrides_the_default() {
16822            test_widgets(|tester| {
16823                pump(
16824                    tester,
16825                    local(
16826                        InputDecorationThemeData::new().is_dense(true),
16827                        InputDecoration::new().label_text(LABEL_TEXT),
16828                    ),
16829                );
16830                assert_eq!(get_container_rect(tester).height(), 48.0);
16831            });
16832        }
16833
16834        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
16835        // contentPadding'.
16836        #[test]
16837        fn a_local_theme_content_padding_overrides_the_default() {
16838            test_widgets(|tester| {
16839                const START: f64 = 11.0;
16840                const TOP: f64 = 13.0;
16841                const END: f64 = 15.0;
16842                const BOTTOM: f64 = 17.0;
16843
16844                pump(
16845                    tester,
16846                    local(
16847                        InputDecorationThemeData::new()
16848                            .content_padding(EdgeInsetsDirectional::only(START, TOP, END, BOTTOM)),
16849                        InputDecoration::new().label_text(LABEL_TEXT),
16850                    ),
16851                );
16852
16853                const LABEL_HEIGHT: f64 = 16.0;
16854                const INPUT_HEIGHT: f64 = 24.0;
16855                assert_eq!(
16856                    get_container_rect(tester).height(),
16857                    TOP + LABEL_HEIGHT + INPUT_HEIGHT + BOTTOM
16858                );
16859                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).left, START);
16860                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).right, 800.0 - END);
16861            });
16862        }
16863
16864        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - isCollapsed'.
16865        #[test]
16866        fn a_local_theme_is_collapsed_overrides_the_default() {
16867            test_widgets(|tester| {
16868                // Overall height for a collapsed InputDecorator is 24dp which is the input
16869                // height (font size = 16, line height = 1.5).
16870                const INPUT_HEIGHT: f64 = 24.0;
16871
16872                pump(
16873                    tester,
16874                    local(
16875                        InputDecorationThemeData::new().is_collapsed(true),
16876                        InputDecoration::new().label_text(LABEL_TEXT),
16877                    )
16878                    .is_focused(true),
16879                );
16880
16881                assert_eq!(
16882                    get_decorator_rect(tester).size(),
16883                    Size::new(800.0, INPUT_HEIGHT)
16884                );
16885            });
16886        }
16887
16888        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - iconColor'.
16889        #[test]
16890        fn a_local_theme_icon_color_overrides_the_default() {
16891            test_widgets(|tester| {
16892                pump(
16893                    tester,
16894                    local(
16895                        InputDecorationThemeData::new().icon_color(indigo()),
16896                        InputDecoration::new().icon(icon(Icons::cabin())),
16897                    ),
16898                );
16899                assert_eq!(icon_theme_color(tester, &Icons::cabin()), Some(indigo()));
16900            });
16901        }
16902
16903        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - prefixStyle'.
16904        #[test]
16905        fn a_local_theme_prefix_style_overrides_the_default() {
16906            test_widgets(|tester| {
16907                const PREFIX_LABEL: &str = "prefix";
16908                pump(
16909                    tester,
16910                    local(
16911                        InputDecorationThemeData::new().prefix_style(indigo_style()),
16912                        InputDecoration::new().prefix(Text::new(PREFIX_LABEL)),
16913                    )
16914                    .is_focused(true),
16915                );
16916                assert_eq!(
16917                    style_color(&rich_text_style(tester, PREFIX_LABEL)),
16918                    Some(indigo())
16919                );
16920            });
16921        }
16922
16923        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
16924        // prefixIconColor'.
16925        #[test]
16926        fn a_local_theme_prefix_icon_color_overrides_the_default() {
16927            test_widgets(|tester| {
16928                pump(
16929                    tester,
16930                    local(
16931                        InputDecorationThemeData::new().prefix_icon_color(indigo()),
16932                        InputDecoration::new().prefix_icon(icon(Icons::cabin())),
16933                    ),
16934                );
16935                assert_eq!(icon_theme_color(tester, &Icons::cabin()), Some(indigo()));
16936            });
16937        }
16938
16939        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
16940        // prefixIconConstraints'.
16941        #[test]
16942        fn a_local_theme_prefix_icon_constraints_override_the_default() {
16943            test_widgets(|tester| {
16944                pump(
16945                    tester,
16946                    local(
16947                        InputDecorationThemeData::new().prefix_icon_constraints(BoxConstraints {
16948                            min_width: 60.0,
16949                            min_height: 60.0,
16950                            ..BoxConstraints::new()
16951                        }),
16952                        InputDecoration::new().prefix_icon(icon(Icons::cabin())),
16953                    ),
16954                );
16955                assert_eq!(icon_size(tester, &Icons::cabin()), Size::new(60.0, 60.0));
16956            });
16957        }
16958
16959        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - suffixStyle'.
16960        #[test]
16961        fn a_local_theme_suffix_style_overrides_the_default() {
16962            test_widgets(|tester| {
16963                const SUFFIX_LABEL: &str = "suffix";
16964                pump(
16965                    tester,
16966                    local(
16967                        InputDecorationThemeData::new().suffix_style(indigo_style()),
16968                        InputDecoration::new().suffix(Text::new(SUFFIX_LABEL)),
16969                    )
16970                    .is_focused(true),
16971                );
16972                assert_eq!(
16973                    style_color(&rich_text_style(tester, SUFFIX_LABEL)),
16974                    Some(indigo())
16975                );
16976            });
16977        }
16978
16979        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
16980        // suffixIconColor'.
16981        #[test]
16982        fn a_local_theme_suffix_icon_color_overrides_the_default() {
16983            test_widgets(|tester| {
16984                pump(
16985                    tester,
16986                    local(
16987                        InputDecorationThemeData::new().suffix_icon_color(indigo()),
16988                        InputDecoration::new().suffix_icon(icon(Icons::cabin())),
16989                    ),
16990                );
16991                assert_eq!(icon_theme_color(tester, &Icons::cabin()), Some(indigo()));
16992            });
16993        }
16994
16995        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
16996        // suffixIconConstraints'.
16997        #[test]
16998        fn a_local_theme_suffix_icon_constraints_override_the_default() {
16999            test_widgets(|tester| {
17000                pump(
17001                    tester,
17002                    local(
17003                        InputDecorationThemeData::new().suffix_icon_constraints(BoxConstraints {
17004                            min_width: 60.0,
17005                            min_height: 60.0,
17006                            ..BoxConstraints::new()
17007                        }),
17008                        InputDecoration::new().suffix_icon(icon(Icons::cabin())),
17009                    ),
17010                );
17011                assert_eq!(icon_size(tester, &Icons::cabin()), Size::new(60.0, 60.0));
17012            });
17013        }
17014
17015        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
17016        // counterStyle'.
17017        #[test]
17018        fn a_local_theme_counter_style_overrides_the_default() {
17019            test_widgets(|tester| {
17020                pump(
17021                    tester,
17022                    local(
17023                        InputDecorationThemeData::new().counter_style(indigo_style()),
17024                        InputDecoration::new()
17025                            .label_text(LABEL_TEXT)
17026                            .counter_text(COUNTER_TEXT),
17027                    ),
17028                );
17029                assert_eq!(
17030                    style_color(&rich_text_style(tester, COUNTER_TEXT)),
17031                    Some(indigo())
17032                );
17033            });
17034        }
17035
17036        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - filled and
17037        // fillColor'.
17038        #[test]
17039        fn a_local_theme_filled_and_fill_color_override_the_default() {
17040            test_widgets(|tester| {
17041                pump(
17042                    tester,
17043                    local(
17044                        InputDecorationThemeData::new()
17045                            .filled(true)
17046                            .fill_color(indigo()),
17047                        InputDecoration::new()
17048                            .label_text(LABEL_TEXT)
17049                            .counter_text(COUNTER_TEXT),
17050                    ),
17051                );
17052                assert_paints(
17053                    &border_painter_ops(tester),
17054                    &[PaintCall::RRect {
17055                        rrect: None,
17056                        color: Some(indigo()),
17057                        style: Some(PaintedStyle::Fill),
17058                        has_mask_filter: None,
17059                    }],
17060                );
17061            });
17062        }
17063
17064        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
17065        // activeIndicatorBorder'.
17066        #[test]
17067        fn a_local_theme_active_indicator_border_overrides_the_default() {
17068            test_widgets(|tester| {
17069                let active_indicator_border = BorderSide {
17070                    color: Colors::AMBER.primary(),
17071                    width: 2.0,
17072                    ..BorderSide::default()
17073                };
17074                pump(
17075                    tester,
17076                    local(
17077                        InputDecorationThemeData::new()
17078                            .filled(true)
17079                            .active_indicator_border(active_indicator_border),
17080                        InputDecoration::new().label_text(LABEL_TEXT),
17081                    ),
17082                );
17083
17084                assert_eq!(get_border_color(tester), active_indicator_border.color);
17085                assert_eq!(get_border_weight(tester), active_indicator_border.width);
17086            });
17087        }
17088
17089        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - hoverColor'.
17090        #[test]
17091        fn a_local_theme_hover_color_overrides_the_default() {
17092            test_widgets(|tester| {
17093                pump(
17094                    tester,
17095                    local(
17096                        InputDecorationThemeData::new()
17097                            .filled(true)
17098                            .hover_color(indigo()),
17099                        InputDecoration::new()
17100                            .label_text(LABEL_TEXT)
17101                            .helper_text(HELPER_TEXT),
17102                    )
17103                    .is_focused(true)
17104                    .is_hovering(true),
17105                );
17106
17107                let theme = {
17108                    let decorator = tester.element(find::by_type::<InputDecorator>());
17109                    let mut app = tester.cell.borrow_mut();
17110                    Theme::of(&mut app, decorator)
17111                };
17112                let focus_color = theme.color_scheme.surface_container_highest();
17113                assert_paints(
17114                    &border_painter_ops(tester),
17115                    &[PaintCall::RRect {
17116                        rrect: None,
17117                        color: Some(Color::alpha_blend(indigo(), focus_color)),
17118                        style: Some(PaintedStyle::Fill),
17119                        has_mask_filter: None,
17120                    }],
17121                );
17122            });
17123        }
17124
17125        fn settled(tester: &mut WidgetTester, decorator: BuildInputDecorator) {
17126            pump(tester, decorator);
17127            tester.pump_and_settle(); // Border changes are animated.
17128        }
17129
17130        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - errorBorder'.
17131        #[test]
17132        fn a_local_theme_error_border_overrides_the_default() {
17133            test_widgets(|tester| {
17134                let error_border = outline(Colors::RED.primary(), 1.5);
17135                settled(
17136                    tester,
17137                    local(
17138                        InputDecorationThemeData::new().error_border(error_border),
17139                        InputDecoration::new().error_text("error"),
17140                    ),
17141                );
17142                assert!(border_is(tester, &error_border));
17143            });
17144        }
17145
17146        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
17147        // focusedErrorBorder'.
17148        #[test]
17149        fn a_local_theme_focused_error_border_overrides_the_default() {
17150            test_widgets(|tester| {
17151                let focused_error_border = outline(Colors::RED.primary(), 1.5);
17152                settled(
17153                    tester,
17154                    local(
17155                        InputDecorationThemeData::new().focused_error_border(focused_error_border),
17156                        InputDecoration::new().error_text("error"),
17157                    )
17158                    .is_focused(true),
17159                );
17160                assert!(border_is(tester, &focused_error_border));
17161            });
17162        }
17163
17164        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
17165        // focusedBorder'.
17166        #[test]
17167        fn a_local_theme_focused_border_overrides_the_default() {
17168            test_widgets(|tester| {
17169                let focused_border = outline(Colors::GREEN.primary(), 1.5);
17170                settled(
17171                    tester,
17172                    local(
17173                        InputDecorationThemeData::new().focused_border(focused_border),
17174                        InputDecoration::new(),
17175                    )
17176                    .is_focused(true),
17177                );
17178                assert!(border_is(tester, &focused_border));
17179            });
17180        }
17181
17182        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
17183        // enabledBorder'.
17184        #[test]
17185        fn a_local_theme_enabled_border_overrides_the_default() {
17186            test_widgets(|tester| {
17187                let enabled_border = outline(Colors::TEAL.primary(), 5.0);
17188                settled(
17189                    tester,
17190                    local(
17191                        InputDecorationThemeData::new().enabled_border(enabled_border),
17192                        InputDecoration::new(),
17193                    ),
17194                );
17195                assert!(border_is(tester, &enabled_border));
17196            });
17197        }
17198
17199        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
17200        // disabledBorder'.
17201        #[test]
17202        fn a_local_theme_disabled_border_overrides_the_default() {
17203            test_widgets(|tester| {
17204                let disabled_border = outline(Colors::TEAL.primary(), 3.0);
17205                settled(
17206                    tester,
17207                    local(
17208                        InputDecorationThemeData::new().disabled_border(disabled_border),
17209                        InputDecoration::new().enabled(false),
17210                    ),
17211                );
17212                assert!(border_is(tester, &disabled_border));
17213            });
17214        }
17215
17216        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - border'.
17217        #[test]
17218        fn a_local_theme_border_overrides_the_default() {
17219            test_widgets(|tester| {
17220                let border_radius = BorderRadius::all(Radius::circular(6.0));
17221                pump(
17222                    tester,
17223                    local(
17224                        InputDecorationThemeData::new()
17225                            .border(OutlineInputBorder::new().border_radius(border_radius)),
17226                        InputDecoration::new(),
17227                    ),
17228                );
17229
17230                // The real instance of border is created based on the given border.
17231                // The type and the borderRadius should be the same as the given border.
17232                assert!(
17233                    get_border(tester)
17234                        .expect("a border")
17235                        .as_any()
17236                        .is::<OutlineInputBorder>()
17237                );
17238                assert_eq!(get_border_radius(tester), Some(border_radius));
17239            });
17240        }
17241
17242        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
17243        // alignLabelWithHint'.
17244        #[test]
17245        fn a_local_theme_align_label_with_hint_overrides_the_default() {
17246            test_widgets(|tester| {
17247                pump(
17248                    tester,
17249                    local(
17250                        InputDecorationThemeData::new().align_label_with_hint(true),
17251                        InputDecoration::new()
17252                            .prefix_icon(icon(Icons::ac_unit()))
17253                            .label_text(LABEL_TEXT)
17254                            .border(OutlineInputBorder::new()),
17255                    )
17256                    .is_focused(true),
17257                );
17258                assert_eq!(
17259                    get_label_rect(tester).left,
17260                    tester.get_rect(find::text(INPUT_TEXT)).left
17261                );
17262            });
17263        }
17264
17265        // input_decorator_test.dart 'Local InputDecorationTheme overrides default - constraints'.
17266        #[test]
17267        fn local_theme_constraints_override_the_default() {
17268            test_widgets(|tester| {
17269                pump(
17270                    tester,
17271                    local(
17272                        InputDecorationThemeData::new().constraints(BoxConstraints {
17273                            max_width: 300.0,
17274                            max_height: 40.0,
17275                            ..BoxConstraints::new()
17276                        }),
17277                        InputDecoration::new().label_text(LABEL_TEXT),
17278                    ),
17279                );
17280
17281                // Theme settings should make it 300x40 pixels.
17282                assert_eq!(get_decorator_rect(tester).size(), Size::new(300.0, 40.0));
17283            });
17284        }
17285
17286        // input_decorator_test.dart 'Local InputDecorationTheme overrides default -
17287        // visualDensity'.
17288        #[test]
17289        fn a_local_theme_visual_density_overrides_the_default() {
17290            test_widgets(|tester| {
17291                pump(
17292                    tester,
17293                    local(
17294                        InputDecorationThemeData::new()
17295                            .visual_density(VisualDensity::new(2.0, 2.0)),
17296                        InputDecoration::new()
17297                            .label_text(LABEL_TEXT)
17298                            .hint_text(HINT_TEXT),
17299                    )
17300                    .is_empty(true),
17301                );
17302
17303                // Overall height for this InputDecorator is 64dp:
17304                //   12 - top padding (8 plus 4 due to increased visual density)
17305                //   12 - floating label (font size = 16 * 0.75, line height is forced to 1.0)
17306                //    4 - gap between label and input (this is not part of the M3 spec)
17307                //   24 - input text (font size = 16, line height = 1.5)
17308                //   12 - bottom padding (8 plus 4 due to increased visual density)
17309                assert_eq!(get_decorator_rect(tester).size().height(), 64.0);
17310            });
17311        }
17312
17313        // input_decorator_test.dart 'Helper and counter are correctly styled'.
17314        #[test]
17315        fn the_focused_filled_helper_and_counter_are_styled_on_surface_variant() {
17316            test_widgets(|tester| {
17317                pump(
17318                    tester,
17319                    BuildInputDecorator::new(
17320                        InputDecoration::new()
17321                            .filled(true)
17322                            .label_text(LABEL_TEXT)
17323                            .helper_text(HELPER_TEXT)
17324                            .counter_text(COUNTER_TEXT),
17325                    )
17326                    .is_focused(true),
17327                );
17328
17329                let theme = {
17330                    let decorator = tester.element(find::by_type::<InputDecorator>());
17331                    let mut app = tester.cell.borrow_mut();
17332                    Theme::of(&mut app, decorator)
17333                };
17334                let expected_color = theme.color_scheme.on_surface_variant();
17335                let expected_style = theme
17336                    .text_theme
17337                    .body_small
17338                    .clone()
17339                    .expect("bodySmall")
17340                    .copy_with()
17341                    .color(expected_color);
17342                assert_eq!(rich_text_style(tester, HELPER_TEXT), expected_style);
17343                assert_eq!(rich_text_style(tester, COUNTER_TEXT), expected_style);
17344            });
17345        }
17346
17347        fn property<T: Clone + std::fmt::Debug + PartialEq + 'static>(
17348            value: T,
17349        ) -> WidgetStatePropertyRef<Option<T>> {
17350            Rc::new(WidgetStatePropertyAll::new(Some(value)))
17351        }
17352
17353        /// Dart's 'Prefix IconButton inherits IconButtonTheme' and its suffix twin.
17354        fn check_icon_button_inherits_icon_button_theme(
17355            tester: &mut WidgetTester,
17356            prefix: bool,
17357            button_icon: IconData,
17358        ) {
17359            let background_color = Color::new(0xffff0000);
17360            let foreground_color = Color::new(0xff00ff00);
17361            let overlay_color = Color::new(0xff0000ff);
17362            let shadow_color = Color::new(0xff0ff0ff);
17363            const ELEVATION: f64 = 4.0;
17364            let shape = RoundedRectangleBorder::new(
17365                BorderSide::NONE,
17366                BorderRadius::all(Radius::circular(10.0)).into(),
17367            );
17368            let icon_button_style = ButtonStyle::new()
17369                .background_color(property(background_color))
17370                .foreground_color(property(foreground_color))
17371                .overlay_color(property(overlay_color))
17372                .shadow_color(property(shadow_color))
17373                .elevation(property(ELEVATION))
17374                .shape(property(OutlinedBorderRef::new(shape)));
17375
17376            let button = IconButton::new(Some(noop()), icon(button_icon.clone()));
17377            let decoration = if prefix {
17378                InputDecoration::new().prefix_icon(button)
17379            } else {
17380                InputDecoration::new().suffix_icon(button)
17381            };
17382            tester.pump_widget(
17383                IconButtonTheme::new(
17384                    IconButtonThemeData::new().style(icon_button_style),
17385                    BuildInputDecorator::new(decoration).build(),
17386                )
17387                .into_widget(),
17388            );
17389
17390            let material = tester.element(
17391                find::descendant(
17392                    find::ancestor(find::by_icon(&button_icon), find::by_type::<IconButton>())
17393                        .first(),
17394                    find::by_type::<Material>(),
17395                )
17396                .first(),
17397            );
17398            tester.widget(material, |material: &Material| {
17399                assert_eq!(material.color, Some(background_color));
17400                assert_eq!(material.shadow_color, Some(shadow_color));
17401                assert_eq!(material.elevation, ELEVATION);
17402                assert!(material.shape.as_ref().expect("a shape").eq_shape(&shape));
17403            });
17404
17405            assert_eq!(
17406                icon_glyph_color(tester, &button_icon),
17407                Some(foreground_color)
17408            );
17409
17410            let center = { tester.get_center(find::by_icon(&button_icon)) };
17411            let mut gesture = TestPointer::mouse(1, 0);
17412            tester.add_pointer(&mut gesture, Offset::ZERO);
17413            tester.move_to(&mut gesture, center, false);
17414            tester.pump_and_settle();
17415            let ink = tester.first::<crate::material::RenderInkFeatures>();
17416            assert_paints(
17417                &tester.painted_ops(waft_rendering::RenderBox::as_object(ink)),
17418                &[PaintCall::rect(Some(overlay_color))],
17419            );
17420        }
17421
17422        // input_decorator_test.dart 'Prefix IconButton inherits IconButtonTheme'.
17423        #[test]
17424        fn a_prefix_icon_button_inherits_the_icon_button_theme() {
17425            test_widgets(|tester| {
17426                check_icon_button_inherits_icon_button_theme(tester, true, Icons::person())
17427            });
17428        }
17429
17430        // input_decorator_test.dart 'Suffix IconButton inherits IconButtonTheme'.
17431        #[test]
17432        fn a_suffix_icon_button_inherits_the_icon_button_theme() {
17433            test_widgets(|tester| {
17434                check_icon_button_inherits_icon_button_theme(tester, false, Icons::delete())
17435            });
17436        }
17437
17438        /// Dart's 'Prefix IconButton color respects IconButtonTheme foreground color states' and
17439        /// its suffix twin.
17440        fn check_icon_button_color_respects_foreground_states(
17441            tester: &mut WidgetTester,
17442            prefix: bool,
17443            button_icon: IconData,
17444        ) {
17445            let icon_error_color = Color::new(0xffff0000);
17446            let icon_color = Color::new(0xff00ff00);
17447            let icon_button_style =
17448                ButtonStyle::new().foreground_color(
17449                    <dyn WidgetStateProperty<Option<Color>>>::resolve_with(move |states| {
17450                        if states.contains(&WidgetState::Error) {
17451                            return Some(icon_error_color);
17452                        }
17453                        Some(icon_color)
17454                    }),
17455                );
17456            let build = |error_text: Option<&str>| {
17457                let button = IconButton::new(Some(noop()), icon(button_icon.clone()));
17458                let mut decoration = if prefix {
17459                    InputDecoration::new().prefix_icon(button)
17460                } else {
17461                    InputDecoration::new().suffix_icon(button)
17462                };
17463                if let Some(error_text) = error_text {
17464                    decoration = decoration.error_text(error_text);
17465                }
17466                BuildInputDecorator::new(decoration)
17467                    .icon_button_theme(IconButtonThemeData::new().style(icon_button_style.clone()))
17468                    .build()
17469            };
17470
17471            // Test the prefix IconButton color when there is an error text.
17472            tester.pump_widget(build(Some("error")));
17473
17474            assert_eq!(
17475                icon_glyph_color(tester, &button_icon),
17476                Some(icon_error_color)
17477            );
17478
17479            // Test the prefix IconButton color when there is no error text.
17480            tester.pump_widget(build(None));
17481            tester.pump_and_settle();
17482
17483            assert_eq!(icon_glyph_color(tester, &button_icon), Some(icon_color));
17484        }
17485
17486        // input_decorator_test.dart 'Prefix IconButton color respects IconButtonTheme foreground
17487        // color states'.
17488        #[test]
17489        fn a_prefix_icon_button_colour_follows_the_icon_button_theme_foreground_states() {
17490            test_widgets(|tester| {
17491                check_icon_button_color_respects_foreground_states(tester, true, Icons::person())
17492            });
17493        }
17494
17495        // input_decorator_test.dart 'Suffix IconButton color respects IconButtonTheme foreground
17496        // color states'.
17497        #[test]
17498        fn a_suffix_icon_button_colour_follows_the_icon_button_theme_foreground_states() {
17499            test_widgets(|tester| {
17500                check_icon_button_color_respects_foreground_states(tester, false, Icons::search())
17501            });
17502        }
17503
17504        // input_decorator_test.dart 'Custom borders - InputDecoration shows custom focused border'.
17505        #[test]
17506        fn a_decoration_shows_its_custom_focused_border() {
17507            test_widgets(|tester| {
17508                let focused_border = outline(Colors::TEAL.primary(), 5.0);
17509                settled(
17510                    tester,
17511                    BuildInputDecorator::new(InputDecoration::new().focused_border(focused_border))
17512                        .is_focused(true),
17513                );
17514                assert!(border_is(tester, &focused_border));
17515            });
17516        }
17517
17518        // input_decorator_test.dart 'Custom borders - InputDecoration shows custom error borders'.
17519        #[test]
17520        fn a_decoration_shows_its_custom_error_borders() {
17521            test_widgets(|tester| {
17522                let error_border = outline(Colors::RED.primary(), 1.5);
17523                let focused_error_border = outline(Colors::TEAL.primary(), 5.0);
17524
17525                let mut check_borders =
17526                    |is_focused: bool,
17527                     enabled: bool,
17528                     error_text: Option<&str>,
17529                     error: Option<WidgetRef>,
17530                     expected_border: &OutlineInputBorder| {
17531                        let mut decoration = InputDecoration::new()
17532                            .enabled(enabled)
17533                            .error_border(error_border)
17534                            .focused_error_border(focused_error_border);
17535                        if let Some(error_text) = error_text {
17536                            decoration = decoration.error_text(error_text);
17537                        }
17538                        if let Some(error) = error {
17539                            decoration = decoration.error(error);
17540                        }
17541                        tester.pump_widget(
17542                            BuildInputDecorator::new(decoration)
17543                                .is_focused(is_focused)
17544                                .build(),
17545                        );
17546                        tester.pump_and_settle(); // Border changes are animated.
17547                        assert!(border_is(tester, expected_border));
17548                    };
17549
17550                // Test with errorText.
17551                check_borders(true, true, Some("error"), None, &focused_error_border);
17552                check_borders(false, true, Some("error"), None, &error_border);
17553                check_borders(false, false, Some("error"), None, &error_border);
17554
17555                // Test with error widget.
17556                let error = || Text::new("error").into_widget();
17557                check_borders(true, true, None, Some(error()), &focused_error_border);
17558                check_borders(false, true, None, Some(error()), &error_border);
17559                check_borders(false, false, None, Some(error()), &error_border);
17560            });
17561        }
17562
17563        // input_decorator_test.dart 'Custom borders - InputDecoration shows custom enabled border'.
17564        #[test]
17565        fn a_decoration_shows_its_custom_enabled_border() {
17566            test_widgets(|tester| {
17567                let enabled_border = outline(Colors::TEAL.primary(), 5.0);
17568                settled(
17569                    tester,
17570                    BuildInputDecorator::new(InputDecoration::new().enabled_border(enabled_border)),
17571                );
17572                assert!(border_is(tester, &enabled_border));
17573            });
17574        }
17575
17576        // input_decorator_test.dart 'Custom borders - InputDecoration shows custom disabled
17577        // border'.
17578        #[test]
17579        fn a_decoration_shows_its_custom_disabled_border() {
17580            test_widgets(|tester| {
17581                let disabled_border = outline(Colors::TEAL.primary(), 3.0);
17582                settled(
17583                    tester,
17584                    BuildInputDecorator::new(
17585                        InputDecoration::new()
17586                            .enabled(false)
17587                            .disabled_border(disabled_border),
17588                    ),
17589                );
17590                assert!(border_is(tester, &disabled_border));
17591            });
17592        }
17593
17594        // input_decorator_test.dart 'InputDecorator.debugDescribeChildren'.
17595        #[test]
17596        fn a_decoration_describes_its_children_by_slot() {
17597            test_widgets(|tester| {
17598                tester.pump_widget(
17599                    BuildInputDecorator::new(
17600                        InputDecoration::new()
17601                            .icon(Text::new("icon"))
17602                            .label_text("label")
17603                            .hint_text("hint")
17604                            .prefix_text("prefix")
17605                            .suffix_text("suffix")
17606                            .prefix_icon(Text::new("prefixIcon"))
17607                            .suffix_icon(Text::new("suffixIcon"))
17608                            .helper_text("helper")
17609                            .counter_text("counter"),
17610                    )
17611                    .child(Text::new("text"))
17612                    .build(),
17613                );
17614
17615                // No Semantics wrapper to walk through: accessibility is deferred, so the
17616                // decorator's element answers with `_RenderDecoration` itself.
17617                let decoration = tester
17618                    .render_object(find::by_type::<InputDecorator>())
17619                    .downcast::<RenderDecoration>(&tester.cell.borrow())
17620                    .expect("the decorator's render object");
17621                let names: Vec<String> = {
17622                    let app = tester.cell.borrow();
17623                    decoration
17624                        .as_object()
17625                        .to_diagnostics_node(&app, None)
17626                        .children()
17627                        .iter()
17628                        .map(|node| node.name().expect("a named child").to_owned())
17629                        .collect()
17630                };
17631                assert_eq!(
17632                    names,
17633                    [
17634                        "icon",
17635                        "input",
17636                        "prefixIcon",
17637                        "suffixIcon",
17638                        "prefix",
17639                        "suffix",
17640                        "label",
17641                        "hint",
17642                        "helperError",
17643                        "counter",
17644                        "container",
17645                    ]
17646                );
17647            });
17648        }
17649    }
17650
17651    // input_decorator_test.dart's 'Material2' group and the
17652    // cases after it.
17653    mod material2_and_layout {
17654        use waft_embedder::{Color, Offset, Rect, Size};
17655        use waft_painting::{
17656            BorderRadius, BorderSide, EdgeInsets, EdgeInsetsGeometry, TextAlignVertical,
17657            TextDirection, TextStyle,
17658        };
17659        use waft_rendering::BoxConstraints;
17660        use waft_widgets::testing::{WidgetTester, test_widgets};
17661        use waft_widgets::{
17662            AnyElement, Builder, Directionality, FadeTransition, GlobalKey, Icon, IntoWidget,
17663            IntrinsicWidth, Padding, SizedBox, WidgetRef, downcast_widget,
17664        };
17665
17666        use super::super::*;
17667        use super::common::*;
17668
17669        use crate::colors::Colors;
17670        use crate::icons::Icons;
17671        use crate::input_border::{InputBorderRef, OutlineInputBorder, UnderlineInputBorder};
17672        use crate::material::Material;
17673        use crate::test_support::material_app;
17674        use crate::text_theme::TextTheme;
17675        use crate::theme::Theme;
17676        use crate::theme_data::{ThemeData, VisualDensity};
17677
17678        const K_MIN_INTERACTIVE_DIMENSION: f64 = 48.0;
17679
17680        /// Dart's `buildInputDecoratorM2`, its named arguments the setters: a Material 2 app whose
17681        /// theme's text theme is `TextTheme(bodyLarge: TextStyle(fontSize: 16.0))`.
17682        struct M2 {
17683            decoration: InputDecoration,
17684            theme: Option<fn(&App) -> ThemeData>,
17685            input_decoration_theme: Option<InputDecorationThemeData>,
17686            text_direction: TextDirection,
17687            expands: bool,
17688            is_empty: bool,
17689            is_focused: bool,
17690            is_hovering: bool,
17691            use_intrinsic_width: bool,
17692            base_style: Option<TextStyle>,
17693            text_align_vertical: Option<TextAlignVertical>,
17694            visual_density: Option<VisualDensity>,
17695            child: Option<WidgetRef>,
17696        }
17697
17698        // The setters are named after Dart's named arguments, as InputDecorator's are.
17699        #[allow(clippy::wrong_self_convention)]
17700        impl M2 {
17701            fn new(decoration: InputDecoration) -> M2 {
17702                M2 {
17703                    decoration,
17704                    theme: None,
17705                    input_decoration_theme: None,
17706                    text_direction: TextDirection::Ltr,
17707                    expands: false,
17708                    is_empty: false,
17709                    is_focused: false,
17710                    is_hovering: false,
17711                    use_intrinsic_width: false,
17712                    base_style: None,
17713                    text_align_vertical: None,
17714                    visual_density: None,
17715                    child: None,
17716                }
17717            }
17718
17719            fn theme(mut self, theme: fn(&App) -> ThemeData) -> M2 {
17720                self.theme = Some(theme);
17721                self
17722            }
17723
17724            fn input_decoration_theme(mut self, theme: InputDecorationThemeData) -> M2 {
17725                self.input_decoration_theme = Some(theme);
17726                self
17727            }
17728
17729            fn text_direction(mut self, text_direction: TextDirection) -> M2 {
17730                self.text_direction = text_direction;
17731                self
17732            }
17733
17734            fn expands(mut self, expands: bool) -> M2 {
17735                self.expands = expands;
17736                self
17737            }
17738
17739            fn is_empty(mut self, is_empty: bool) -> M2 {
17740                self.is_empty = is_empty;
17741                self
17742            }
17743
17744            fn is_focused(mut self, is_focused: bool) -> M2 {
17745                self.is_focused = is_focused;
17746                self
17747            }
17748
17749            fn is_hovering(mut self, is_hovering: bool) -> M2 {
17750                self.is_hovering = is_hovering;
17751                self
17752            }
17753
17754            fn use_intrinsic_width(mut self, use_intrinsic_width: bool) -> M2 {
17755                self.use_intrinsic_width = use_intrinsic_width;
17756                self
17757            }
17758
17759            fn base_style(mut self, base_style: TextStyle) -> M2 {
17760                self.base_style = Some(base_style);
17761                self
17762            }
17763
17764            fn text_align_vertical(mut self, text_align_vertical: TextAlignVertical) -> M2 {
17765                self.text_align_vertical = Some(text_align_vertical);
17766                self
17767            }
17768
17769            fn visual_density(mut self, visual_density: VisualDensity) -> M2 {
17770                self.visual_density = Some(visual_density);
17771                self
17772            }
17773
17774            fn child<K>(mut self, child: impl IntoWidget<K>) -> M2 {
17775                self.child = Some(child.into_widget());
17776                self
17777            }
17778
17779            /// Dart's `tester.pumpWidget(buildInputDecoratorM2(..))`.
17780            fn pump(self, tester: &mut WidgetTester) {
17781                let widget = self.build(tester);
17782                tester.pump_widget(widget);
17783            }
17784
17785            /// Dart's `buildInputDecoratorM2(..)`.
17786            fn build(self, tester: &WidgetTester) -> WidgetRef {
17787                let mut decorator = InputDecorator::new(self.decoration)
17788                    .expands(self.expands)
17789                    .is_empty(self.is_empty)
17790                    .is_focused(self.is_focused)
17791                    .is_hovering(self.is_hovering)
17792                    .child(self.child.unwrap_or_else(m2_input_text));
17793                if let Some(base_style) = self.base_style {
17794                    decorator = decorator.base_style(base_style);
17795                }
17796                if let Some(text_align_vertical) = self.text_align_vertical {
17797                    decorator = decorator.text_align_vertical(text_align_vertical);
17798                }
17799                let mut widget = decorator.into_widget();
17800                if self.use_intrinsic_width {
17801                    widget = IntrinsicWidth::new().child(widget).into_widget();
17802                }
17803
17804                let theme = self.theme;
17805                let input_decoration_theme = self.input_decoration_theme;
17806                let visual_density = self.visual_density;
17807                let text_direction = self.text_direction;
17808                let home = Material::new().child(Builder::new(move |app, context| {
17809                    let base = match theme {
17810                        Some(theme) => Rc::new(theme(app)),
17811                        None => Theme::of(app, context),
17812                    };
17813                    let mut copy = base.copy_with();
17814                    if let Some(input_decoration_theme) = &input_decoration_theme {
17815                        copy = copy.input_decoration_theme(input_decoration_theme.clone());
17816                    }
17817                    if let Some(visual_density) = visual_density {
17818                        copy = copy.visual_density(visual_density);
17819                    }
17820                    copy = copy
17821                        .text_theme(TextTheme::new().body_large(TextStyle::new().font_size(16.0)));
17822                    Theme::new(
17823                        copy.build(),
17824                        waft_widgets::Align::new()
17825                            .alignment(waft_painting::AlignmentGeometry::Alignment(
17826                                waft_painting::Alignment::TOP_LEFT,
17827                            ))
17828                            .child(Directionality::new(text_direction, widget.clone())),
17829                    )
17830                    .into_widget()
17831                }));
17832                let app_theme = m2(&tester.cell.borrow());
17833                material_app(app_theme, home.into_widget())
17834            }
17835        }
17836
17837        /// Dart's M2 input child: `Text('text', style: TextStyle(fontSize: 16.0))`.
17838        fn m2_input_text() -> WidgetRef {
17839            Text::new(INPUT_TEXT)
17840                .style(TextStyle::new().font_size(16.0))
17841                .into_widget()
17842        }
17843
17844        fn top(tester: &WidgetTester, text: &str) -> f64 {
17845            tester.get_rect(find::text(text)).top
17846        }
17847
17848        fn bottom(tester: &WidgetTester, text: &str) -> f64 {
17849            tester.get_rect(find::text(text)).bottom
17850        }
17851
17852        fn decorator_size(tester: &WidgetTester) -> Size {
17853            get_decorator_rect(tester).size()
17854        }
17855
17856        fn key_rect(tester: &WidgetTester, key: &GlobalKey) -> Rect {
17857            let render = tester.render_object(key).as_box().expect("a render box");
17858            tester.get_rect(render)
17859        }
17860
17861        fn sized(key: &GlobalKey, width: f64, height: f64) -> WidgetRef {
17862            SizedBox::new()
17863                .key(key.clone().into())
17864                .width(width)
17865                .height(height)
17866                .into_widget()
17867        }
17868
17869        fn icon_rect(tester: &WidgetTester, icon: &waft_widgets::IconData) -> Rect {
17870            tester.get_rect(find::by_icon(icon))
17871        }
17872
17873        /// Dart's `getOpacity(tester, text)`: the value of the nearest `FadeTransition` above the
17874        /// `Text` showing `text`.
17875        fn get_opacity(tester: &WidgetTester, text: &str) -> f64 {
17876            let element = tester.element(find::text(text));
17877            let fade = tester
17878                .ancestors(element)
17879                .into_iter()
17880                .find(|ancestor: &AnyElement| {
17881                    let app = tester.cell.borrow();
17882                    downcast_widget::<FadeTransition>(&**ancestor.widget(&app)).is_some()
17883                })
17884                .expect("a FadeTransition above the text");
17885            let opacity = tester.widget(fade, |fade: &FadeTransition| fade.opacity.clone());
17886            opacity.value(&tester.cell.borrow())
17887        }
17888
17889        fn in_exclusive_range(value: f64, low: f64, high: f64) -> bool {
17890            low < value && value < high
17891        }
17892
17893        // input_decorator_test.dart 'Material2 - InputDecorator input/label text layout'.
17894        #[test]
17895        fn material2_input_and_label_text_layout() {
17896            test_widgets(|tester| {
17897                // The label appears above the input text
17898                M2::new(InputDecoration::new().label_text(LABEL_TEXT)).pump(tester);
17899                tester.pump_and_settle();
17900
17901                // Overall height for this InputDecorator is 56dps:
17902                //   12 - top padding
17903                //   12 - floating label (font size 16dps * 0.75 = 12)
17904                //    4 - floating label / input text gap
17905                //   16 - input text (font size 16dps)
17906                //   12 - bottom padding
17907                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
17908                assert_eq!(top(tester, INPUT_TEXT), 28.0);
17909                assert_eq!(bottom(tester, INPUT_TEXT), 44.0);
17910                assert_eq!(top(tester, LABEL_TEXT), 12.0);
17911                assert_eq!(bottom(tester, LABEL_TEXT), 24.0);
17912                assert_eq!(get_border_bottom(tester), 56.0);
17913                assert_eq!(get_border_weight(tester), 1.0);
17914
17915                // The label appears within the input when there is no text content
17916                M2::new(InputDecoration::new().label_text(LABEL_TEXT))
17917                    .is_empty(true)
17918                    .pump(tester);
17919                tester.pump_and_settle();
17920                assert_eq!(top(tester, LABEL_TEXT), 20.0);
17921
17922                // The label appears above the input text when there is no content and
17923                // floatingLabelBehavior is always
17924                M2::new(
17925                    InputDecoration::new()
17926                        .label_text(LABEL_TEXT)
17927                        .floating_label_behavior(FloatingLabelBehavior::Always),
17928                )
17929                .is_empty(true)
17930                .pump(tester);
17931                tester.pump_and_settle();
17932                assert_eq!(top(tester, LABEL_TEXT), 12.0);
17933
17934                // The label appears within the input text when there is content and
17935                // floatingLabelBehavior is never
17936                M2::new(
17937                    InputDecoration::new()
17938                        .label_text(LABEL_TEXT)
17939                        .floating_label_behavior(FloatingLabelBehavior::Never),
17940                )
17941                .pump(tester);
17942                tester.pump_and_settle();
17943                assert_eq!(top(tester, LABEL_TEXT), 20.0);
17944
17945                // isFocused: true increases the border's weight from 1.0 to 2.0
17946                // but does not change the overall height.
17947                M2::new(InputDecoration::new().label_text(LABEL_TEXT))
17948                    .is_focused(true)
17949                    .pump(tester);
17950                tester.pump_and_settle();
17951                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
17952                assert_eq!(top(tester, INPUT_TEXT), 28.0);
17953                assert_eq!(bottom(tester, INPUT_TEXT), 44.0);
17954                assert_eq!(top(tester, LABEL_TEXT), 12.0);
17955                assert_eq!(bottom(tester, LABEL_TEXT), 24.0);
17956                assert_eq!(get_border_bottom(tester), 56.0);
17957                assert_eq!(get_border_weight(tester), 2.0);
17958
17959                // isEmpty: true causes the label to be aligned with the input text
17960                M2::new(InputDecoration::new().label_text(LABEL_TEXT))
17961                    .is_empty(true)
17962                    .pump(tester);
17963
17964                // The label animates downwards from it's initial position
17965                // above the input text. The animation's duration is 167ms.
17966                tester.pump_by(Duration::from_millis(50));
17967                let label_y_50ms = top(tester, LABEL_TEXT);
17968                assert!(
17969                    in_exclusive_range(label_y_50ms, 12.0, 20.0),
17970                    "{label_y_50ms}"
17971                );
17972                tester.pump_by(Duration::from_millis(50));
17973                let label_y_100ms = top(tester, LABEL_TEXT);
17974                assert!(
17975                    in_exclusive_range(label_y_100ms, label_y_50ms, 20.0),
17976                    "{label_y_100ms}"
17977                );
17978                tester.pump_and_settle();
17979                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
17980                assert_eq!(top(tester, INPUT_TEXT), 28.0);
17981                assert_eq!(bottom(tester, INPUT_TEXT), 44.0);
17982                assert_eq!(top(tester, LABEL_TEXT), 20.0);
17983                assert_eq!(bottom(tester, LABEL_TEXT), 36.0);
17984                assert_eq!(get_border_bottom(tester), 56.0);
17985                assert_eq!(get_border_weight(tester), 1.0);
17986
17987                // isFocused: true causes the label to move back up above the input text.
17988                M2::new(InputDecoration::new().label_text(LABEL_TEXT))
17989                    .is_empty(true)
17990                    .is_focused(true)
17991                    .pump(tester);
17992
17993                // The label animates upwards from it's initial position
17994                // above the input text. The animation's duration is 167ms.
17995                tester.pump_by(Duration::from_millis(50));
17996                let label_y_50ms = top(tester, LABEL_TEXT);
17997                assert!(
17998                    in_exclusive_range(label_y_50ms, 12.0, 28.0),
17999                    "{label_y_50ms}"
18000                );
18001                tester.pump_by(Duration::from_millis(50));
18002                let label_y_100ms = top(tester, LABEL_TEXT);
18003                assert!(
18004                    in_exclusive_range(label_y_100ms, 12.0, label_y_50ms),
18005                    "{label_y_100ms}"
18006                );
18007
18008                tester.pump_and_settle();
18009                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
18010                assert_eq!(top(tester, INPUT_TEXT), 28.0);
18011                assert_eq!(bottom(tester, INPUT_TEXT), 44.0);
18012                assert_eq!(top(tester, LABEL_TEXT), 12.0);
18013                assert_eq!(bottom(tester, LABEL_TEXT), 24.0);
18014                assert_eq!(get_border_bottom(tester), 56.0);
18015                assert_eq!(get_border_weight(tester), 2.0);
18016
18017                // enabled: false produces a hairline border if filled: false (the default)
18018                // The widget's size and layout is the same as for enabled: true.
18019                M2::new(InputDecoration::new().label_text(LABEL_TEXT).enabled(false))
18020                    .is_empty(true)
18021                    .pump(tester);
18022                tester.pump_and_settle();
18023                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
18024                assert_eq!(top(tester, INPUT_TEXT), 28.0);
18025                assert_eq!(bottom(tester, INPUT_TEXT), 44.0);
18026                assert_eq!(top(tester, LABEL_TEXT), 20.0);
18027                assert_eq!(bottom(tester, LABEL_TEXT), 36.0);
18028                assert_eq!(get_border_weight(tester), 0.0);
18029
18030                // enabled: false produces a transparent border if filled: true.
18031                // The widget's size and layout is the same as for enabled: true.
18032                M2::new(
18033                    InputDecoration::new()
18034                        .label_text(LABEL_TEXT)
18035                        .enabled(false)
18036                        .filled(true),
18037                )
18038                .is_empty(true)
18039                .pump(tester);
18040                tester.pump_and_settle();
18041                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
18042                assert_eq!(top(tester, INPUT_TEXT), 28.0);
18043                assert_eq!(bottom(tester, INPUT_TEXT), 44.0);
18044                assert_eq!(top(tester, LABEL_TEXT), 20.0);
18045                assert_eq!(bottom(tester, LABEL_TEXT), 36.0);
18046                assert_eq!(get_border_color(tester), Colors::TRANSPARENT);
18047
18048                // alignLabelWithHint: true positions the label at the text baseline,
18049                // aligned with the hint.
18050                M2::new(
18051                    InputDecoration::new()
18052                        .label_text(LABEL_TEXT)
18053                        .align_label_with_hint(true)
18054                        .hint_text(HINT_TEXT),
18055                )
18056                .is_empty(true)
18057                .pump(tester);
18058                tester.pump_and_settle();
18059                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
18060                assert_eq!(top(tester, LABEL_TEXT), top(tester, HINT_TEXT));
18061                assert_eq!(bottom(tester, LABEL_TEXT), bottom(tester, HINT_TEXT));
18062            });
18063        }
18064
18065        fn pump_floating_label(tester: &mut WidgetTester, is_focused: bool) {
18066            M2::new(
18067                InputDecoration::new()
18068                    .label_text(LABEL_TEXT)
18069                    .floating_label_behavior(FloatingLabelBehavior::Auto),
18070            )
18071            .is_empty(true)
18072            .is_focused(is_focused)
18073            .pump(tester);
18074        }
18075
18076        // input_decorator_test.dart 'Material2 - InputDecorator floating label animation duration
18077        // and curve'.
18078        #[test]
18079        fn material2_floating_label_animation_duration_and_curve() {
18080            test_widgets(|tester| {
18081                pump_floating_label(tester, false);
18082                assert_eq!(top(tester, LABEL_TEXT), 20.0);
18083
18084                // The label animates upwards and scales down.
18085                // The animation duration is 167ms and the curve is fastOutSlowIn.
18086                pump_floating_label(tester, true);
18087                tester.pump_by(Duration::from_millis(42));
18088                assert_more_or_less_equals_within(top(tester, LABEL_TEXT), 18.06, 0.5);
18089                tester.pump_by(Duration::from_millis(42));
18090                assert_more_or_less_equals_within(top(tester, LABEL_TEXT), 13.78, 0.5);
18091                tester.pump_by(Duration::from_millis(42));
18092                assert_more_or_less_equals_within(top(tester, LABEL_TEXT), 12.31, 0.5);
18093                tester.pump_by(Duration::from_millis(41));
18094                assert_eq!(top(tester, LABEL_TEXT), 12.0);
18095
18096                // If the animation changes direction without first reaching the
18097                // AnimationStatus.completed or AnimationStatus.dismissed status,
18098                // the CurvedAnimation stays on the same curve in the opposite direction.
18099                // The pumpAndSettle is used to prevent this behavior.
18100                tester.pump_and_settle();
18101
18102                // The label animates downwards and scales up.
18103                // The animation duration is 167ms and the curve is fastOutSlowIn.
18104                pump_floating_label(tester, false);
18105                tester.pump_by(Duration::from_millis(42));
18106                assert_more_or_less_equals_within(top(tester, LABEL_TEXT), 13.94, 0.5);
18107                tester.pump_by(Duration::from_millis(42));
18108                assert_more_or_less_equals_within(top(tester, LABEL_TEXT), 18.22, 0.5);
18109                tester.pump_by(Duration::from_millis(42));
18110                assert_more_or_less_equals_within(top(tester, LABEL_TEXT), 19.69, 0.5);
18111                tester.pump_by(Duration::from_millis(41));
18112                assert_eq!(top(tester, LABEL_TEXT), 20.0);
18113            });
18114        }
18115
18116        // input_decorator_test.dart 'Material2 - InputDecorator input/hint layout'.
18117        #[test]
18118        fn material2_input_and_hint_layout() {
18119            test_widgets(|tester| {
18120                // The hint aligns with the input text
18121                M2::new(InputDecoration::new().hint_text(HINT_TEXT))
18122                    .is_empty(true)
18123                    .pump(tester);
18124
18125                assert_eq!(
18126                    decorator_size(tester),
18127                    Size::new(800.0, K_MIN_INTERACTIVE_DIMENSION)
18128                );
18129                assert_eq!(top(tester, INPUT_TEXT), 16.0);
18130                assert_eq!(bottom(tester, INPUT_TEXT), 32.0);
18131                assert_eq!(top(tester, HINT_TEXT), 16.0);
18132                assert_eq!(bottom(tester, HINT_TEXT), 32.0);
18133                assert_eq!(get_border_bottom(tester), 48.0);
18134                assert_eq!(get_border_weight(tester), 1.0);
18135
18136                assert_eq!(
18137                    tester.get_rect(find::text(HINT_TEXT)).width(),
18138                    tester.get_rect(find::text(INPUT_TEXT)).width()
18139                );
18140            });
18141        }
18142
18143        fn label_and_hint() -> InputDecoration {
18144            InputDecoration::new()
18145                .label_text(LABEL_TEXT)
18146                .hint_text(HINT_TEXT)
18147        }
18148
18149        // input_decorator_test.dart 'Material2 - InputDecorator input/label/hint layout'.
18150        #[test]
18151        fn material2_input_label_and_hint_layout() {
18152            test_widgets(|tester| {
18153                // Label is visible, hint is not (opacity 0.0).
18154                M2::new(label_and_hint()).is_empty(true).pump(tester);
18155
18156                // The label is not floating so it's vertically centered.
18157                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
18158                assert_eq!(top(tester, INPUT_TEXT), 28.0);
18159                assert_eq!(bottom(tester, INPUT_TEXT), 44.0);
18160                assert_eq!(top(tester, LABEL_TEXT), 20.0);
18161                assert_eq!(bottom(tester, LABEL_TEXT), 36.0);
18162                assert_eq!(get_opacity(tester, HINT_TEXT), 0.0);
18163                assert_eq!(get_border_bottom(tester), 56.0);
18164                assert_eq!(get_border_weight(tester), 1.0);
18165
18166                // Label moves upwards, hint is visible (opacity 1.0).
18167                M2::new(label_and_hint())
18168                    .is_empty(true)
18169                    .is_focused(true)
18170                    .pump(tester);
18171
18172                // The hint's opacity animates from 0.0 to 1.0.
18173                // The animation's default duration is 20ms.
18174                tester.pump_by(Duration::from_millis(9));
18175                let hint_opacity_9ms = get_opacity(tester, HINT_TEXT);
18176                assert!(in_exclusive_range(hint_opacity_9ms, 0.0, 1.0));
18177                tester.pump_by(Duration::from_millis(9));
18178                let hint_opacity_18ms = get_opacity(tester, HINT_TEXT);
18179                assert!(in_exclusive_range(hint_opacity_18ms, hint_opacity_9ms, 1.0));
18180
18181                tester.pump_and_settle();
18182                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
18183                assert_eq!(top(tester, INPUT_TEXT), 28.0);
18184                assert_eq!(bottom(tester, INPUT_TEXT), 44.0);
18185                assert_eq!(top(tester, LABEL_TEXT), 12.0);
18186                assert_eq!(bottom(tester, LABEL_TEXT), 24.0);
18187                assert_eq!(top(tester, HINT_TEXT), 28.0);
18188                assert_eq!(bottom(tester, HINT_TEXT), 44.0);
18189                assert_eq!(get_opacity(tester, HINT_TEXT), 1.0);
18190                assert_eq!(get_border_bottom(tester), 56.0);
18191                assert_eq!(get_border_weight(tester), 2.0);
18192
18193                M2::new(label_and_hint()).is_focused(true).pump(tester);
18194
18195                // The hint's opacity animates from 1.0 to 0.0.
18196                // The animation's default duration is 20ms.
18197                tester.pump_by(Duration::from_millis(9));
18198                let hint_opacity_9ms = get_opacity(tester, HINT_TEXT);
18199                assert!(in_exclusive_range(hint_opacity_9ms, 0.0, 1.0));
18200                tester.pump_by(Duration::from_millis(9));
18201                let hint_opacity_18ms = get_opacity(tester, HINT_TEXT);
18202                assert!(in_exclusive_range(hint_opacity_18ms, 0.0, hint_opacity_9ms));
18203
18204                tester.pump_and_settle();
18205                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
18206                assert_eq!(top(tester, INPUT_TEXT), 28.0);
18207                assert_eq!(bottom(tester, INPUT_TEXT), 44.0);
18208                assert_eq!(top(tester, LABEL_TEXT), 12.0);
18209                assert_eq!(bottom(tester, LABEL_TEXT), 24.0);
18210                assert_eq!(top(tester, HINT_TEXT), 28.0);
18211                assert_eq!(bottom(tester, HINT_TEXT), 44.0);
18212                assert_eq!(get_opacity(tester, HINT_TEXT), 0.0);
18213                assert_eq!(get_border_bottom(tester), 56.0);
18214                assert_eq!(get_border_weight(tester), 2.0);
18215            });
18216        }
18217
18218        // input_decorator_test.dart 'Material2 - InputDecorator input/label/hint dense layout'.
18219        #[test]
18220        fn material2_input_label_and_hint_dense_layout() {
18221            test_widgets(|tester| {
18222                // Label is visible, hint is not (opacity 0.0).
18223                M2::new(label_and_hint().is_dense(true))
18224                    .is_empty(true)
18225                    .pump(tester);
18226
18227                // The label is not floating so it's vertically centered.
18228                assert_eq!(decorator_size(tester), Size::new(800.0, 48.0));
18229                assert_eq!(top(tester, INPUT_TEXT), 24.0);
18230                assert_eq!(bottom(tester, INPUT_TEXT), 40.0);
18231                assert_eq!(top(tester, LABEL_TEXT), 16.0);
18232                assert_eq!(bottom(tester, LABEL_TEXT), 32.0);
18233                assert_eq!(get_opacity(tester, HINT_TEXT), 0.0);
18234                assert_eq!(get_border_bottom(tester), 48.0);
18235                assert_eq!(get_border_weight(tester), 1.0);
18236
18237                // Label is visible, hint is not (opacity 0.0).
18238                M2::new(label_and_hint().is_dense(true))
18239                    .is_empty(true)
18240                    .is_focused(true)
18241                    .pump(tester);
18242                tester.pump_and_settle();
18243                assert_eq!(decorator_size(tester), Size::new(800.0, 48.0));
18244                assert_eq!(top(tester, INPUT_TEXT), 24.0);
18245                assert_eq!(bottom(tester, INPUT_TEXT), 40.0);
18246                assert_eq!(top(tester, LABEL_TEXT), 8.0);
18247                assert_eq!(bottom(tester, LABEL_TEXT), 20.0);
18248                assert_eq!(get_opacity(tester, HINT_TEXT), 1.0);
18249                assert_eq!(get_border_bottom(tester), 48.0);
18250                assert_eq!(get_border_weight(tester), 2.0);
18251            });
18252        }
18253
18254        /// The shared steps of the three hint animation duration cases: the hint fades in when the
18255        /// field gets the focus and out when it loses it, over `step` three times.
18256        fn check_hint_fade(tester: &mut WidgetTester, build: impl Fn(bool) -> M2, step: Duration) {
18257            build(false).pump(tester);
18258
18259            // The hint is not visible (opacity 0.0).
18260            assert_eq!(get_opacity(tester, HINT_TEXT), 0.0);
18261
18262            // Focus to show the hint.
18263            build(true).pump(tester);
18264
18265            // The hint's opacity animates from 0.0 to 1.0.
18266            tester.pump_by(step);
18267            let first = get_opacity(tester, HINT_TEXT);
18268            assert!(in_exclusive_range(first, 0.0, 1.0), "{first}");
18269            tester.pump_by(step);
18270            let second = get_opacity(tester, HINT_TEXT);
18271            assert!(in_exclusive_range(second, first, 1.0), "{second}");
18272            tester.pump_by(step);
18273            assert_eq!(get_opacity(tester, HINT_TEXT), 1.0);
18274
18275            // Unfocus to hide the hint.
18276            build(false).pump(tester);
18277
18278            // The hint's opacity animates from 1.0 to 0.0.
18279            tester.pump_by(step);
18280            let first = get_opacity(tester, HINT_TEXT);
18281            assert!(in_exclusive_range(first, 0.0, 1.0), "{first}");
18282            tester.pump_by(step);
18283            let second = get_opacity(tester, HINT_TEXT);
18284            assert!(in_exclusive_range(second, 0.0, first), "{second}");
18285            tester.pump_by(step);
18286            assert_eq!(get_opacity(tester, HINT_TEXT), 0.0);
18287        }
18288
18289        // input_decorator_test.dart 'Material2 - InputDecorator default hint animation duration'.
18290        #[test]
18291        fn material2_default_hint_animation_duration() {
18292            test_widgets(|tester| {
18293                check_hint_fade(
18294                    tester,
18295                    |is_focused| {
18296                        M2::new(label_and_hint())
18297                            .is_empty(true)
18298                            .is_focused(is_focused)
18299                    },
18300                    Duration::from_millis(9),
18301                );
18302            });
18303        }
18304
18305        // input_decorator_test.dart 'Material2 - InputDecorator custom hint animation duration'.
18306        #[test]
18307        fn material2_custom_hint_animation_duration() {
18308            test_widgets(|tester| {
18309                check_hint_fade(
18310                    tester,
18311                    |is_focused| {
18312                        M2::new(label_and_hint().hint_fade_duration(Duration::from_millis(120)))
18313                            .is_empty(true)
18314                            .is_focused(is_focused)
18315                    },
18316                    Duration::from_millis(50),
18317                );
18318            });
18319        }
18320
18321        // input_decorator_test.dart 'Material2 - InputDecorator custom hint animation duration from
18322        // theme'.
18323        #[test]
18324        fn material2_custom_hint_animation_duration_from_theme() {
18325            test_widgets(|tester| {
18326                check_hint_fade(
18327                    tester,
18328                    |is_focused| {
18329                        M2::new(label_and_hint())
18330                            .input_decoration_theme(
18331                                InputDecorationThemeData::new()
18332                                    .hint_fade_duration(Duration::from_millis(120)),
18333                            )
18334                            .is_empty(true)
18335                            .is_focused(is_focused)
18336                    },
18337                    Duration::from_millis(50),
18338                );
18339            });
18340        }
18341
18342        // input_decorator_test.dart 'Material2 - InputDecorator with no input border'.
18343        #[test]
18344        fn material2_decorator_with_no_input_border_has_a_zero_weight_border() {
18345            test_widgets(|tester| {
18346                M2::new(InputDecoration::new().border(InputBorderRef::none()))
18347                    .is_empty(true)
18348                    .pump(tester);
18349                assert_eq!(get_border_weight(tester), 0.0);
18350            });
18351        }
18352
18353        // input_decorator_test.dart 'Material2 - InputDecorator error/helper/counter layout'.
18354        #[test]
18355        fn material2_error_helper_and_counter_layout() {
18356            test_widgets(|tester| {
18357                M2::new(
18358                    InputDecoration::new()
18359                        .label_text(LABEL_TEXT)
18360                        .helper_text(HELPER_TEXT)
18361                        .counter_text(COUNTER_TEXT)
18362                        .filled(true),
18363                )
18364                .is_empty(true)
18365                .pump(tester);
18366
18367                // isEmpty: true, the label is not floating
18368                assert_eq!(decorator_size(tester), Size::new(800.0, 76.0));
18369                assert_eq!(top(tester, INPUT_TEXT), 28.0);
18370                assert_eq!(bottom(tester, INPUT_TEXT), 44.0);
18371                assert_eq!(top(tester, LABEL_TEXT), 20.0);
18372                assert_eq!(bottom(tester, LABEL_TEXT), 36.0);
18373                assert_eq!(get_border_bottom(tester), 56.0);
18374                assert_eq!(get_border_weight(tester), 1.0);
18375                assert_eq!(
18376                    tester.get_rect(find::text(HELPER_TEXT)).top_left(),
18377                    Offset::new(12.0, 64.0)
18378                );
18379                assert_eq!(
18380                    tester.get_rect(find::text(COUNTER_TEXT)).top_right(),
18381                    Offset::new(788.0, 64.0)
18382                );
18383
18384                // If errorText is specified then the helperText isn't shown
18385                M2::new(
18386                    InputDecoration::new()
18387                        .label_text(LABEL_TEXT)
18388                        .error_text(ERROR_TEXT)
18389                        .helper_text(HELPER_TEXT)
18390                        .counter_text(COUNTER_TEXT)
18391                        .filled(true),
18392                )
18393                .pump(tester);
18394                tester.pump_and_settle();
18395
18396                // isEmpty: false, the label _is_ floating
18397                assert_eq!(decorator_size(tester), Size::new(800.0, 76.0));
18398                assert_eq!(top(tester, INPUT_TEXT), 28.0);
18399                assert_eq!(bottom(tester, INPUT_TEXT), 44.0);
18400                assert_eq!(top(tester, LABEL_TEXT), 12.0);
18401                assert_eq!(bottom(tester, LABEL_TEXT), 24.0);
18402                assert_eq!(get_border_bottom(tester), 56.0);
18403                assert_eq!(get_border_weight(tester), 1.0);
18404                assert_eq!(
18405                    tester.get_rect(find::text(ERROR_TEXT)).top_left(),
18406                    Offset::new(12.0, 64.0)
18407                );
18408                assert_eq!(
18409                    tester.get_rect(find::text(COUNTER_TEXT)).top_right(),
18410                    Offset::new(788.0, 64.0)
18411                );
18412                expect(tester, &find::text(HELPER_TEXT), finds_nothing());
18413
18414                // The layout of the error/helper/counter supportingText doesn't change for dense
18415                // layout.
18416                M2::new(
18417                    InputDecoration::new()
18418                        .is_dense(true)
18419                        .label_text(LABEL_TEXT)
18420                        .error_text(ERROR_TEXT)
18421                        .helper_text(HELPER_TEXT)
18422                        .counter_text(COUNTER_TEXT)
18423                        .filled(true),
18424                )
18425                .pump(tester);
18426                tester.pump_and_settle();
18427
18428                // isEmpty: false, the label _is_ floating
18429                assert_eq!(decorator_size(tester), Size::new(800.0, 68.0));
18430                assert_eq!(top(tester, INPUT_TEXT), 24.0);
18431                assert_eq!(bottom(tester, INPUT_TEXT), 40.0);
18432                assert_eq!(top(tester, LABEL_TEXT), 8.0);
18433                assert_eq!(bottom(tester, LABEL_TEXT), 20.0);
18434                assert_eq!(get_border_bottom(tester), 48.0);
18435                assert_eq!(get_border_weight(tester), 1.0);
18436                assert_eq!(
18437                    tester.get_rect(find::text(ERROR_TEXT)).top_left(),
18438                    Offset::new(12.0, 56.0)
18439                );
18440                assert_eq!(
18441                    tester.get_rect(find::text(COUNTER_TEXT)).top_right(),
18442                    Offset::new(788.0, 56.0)
18443                );
18444
18445                M2::new(
18446                    InputDecoration::new()
18447                        .is_dense(true)
18448                        .label_text(LABEL_TEXT)
18449                        .error_text(ERROR_TEXT)
18450                        .helper_text(HELPER_TEXT)
18451                        .counter_text(COUNTER_TEXT)
18452                        .filled(true),
18453                )
18454                .is_empty(true)
18455                .pump(tester);
18456                tester.pump_and_settle();
18457
18458                // isEmpty: false, the label is not floating
18459                assert_eq!(decorator_size(tester), Size::new(800.0, 68.0));
18460                assert_eq!(top(tester, INPUT_TEXT), 24.0);
18461                assert_eq!(bottom(tester, INPUT_TEXT), 40.0);
18462                assert_eq!(top(tester, LABEL_TEXT), 16.0);
18463                assert_eq!(bottom(tester, LABEL_TEXT), 32.0);
18464                assert_eq!(get_border_bottom(tester), 48.0);
18465                assert_eq!(get_border_weight(tester), 1.0);
18466                assert_eq!(
18467                    tester.get_rect(find::text(ERROR_TEXT)).top_left(),
18468                    Offset::new(12.0, 56.0)
18469                );
18470                assert_eq!(
18471                    tester.get_rect(find::text(COUNTER_TEXT)).top_right(),
18472                    Offset::new(788.0, 56.0)
18473                );
18474            });
18475        }
18476
18477        fn error_border() -> InputBorderRef {
18478            InputBorderRef::new(OutlineInputBorder::new().border_side(BorderSide {
18479                color: Colors::RED.primary(),
18480                width: 1.5,
18481                ..BorderSide::default()
18482            }))
18483        }
18484
18485        fn focused_error_border() -> InputBorderRef {
18486            InputBorderRef::new(OutlineInputBorder::new().border_side(BorderSide {
18487                color: Colors::TEAL.primary(),
18488                width: 5.0,
18489                ..BorderSide::default()
18490            }))
18491        }
18492
18493        // input_decorator_test.dart 'Material2 - InputDecoration shows error border for errorText and
18494        // error widget'. The `errorText` steps keep Dart's string; the `error` steps hand a widget.
18495        #[test]
18496        fn material2_error_border_shows_for_error_text_and_error_widget() {
18497            test_widgets(|tester| {
18498                let with_text = || {
18499                    InputDecoration::new()
18500                        .error_text(ERROR_TEXT)
18501                        .error_border(error_border())
18502                        .focused_error_border(focused_error_border())
18503                };
18504                let with_widget = || {
18505                    InputDecoration::new()
18506                        .error(waft_widgets::Text::new(ERROR_TEXT))
18507                        .error_border(error_border())
18508                        .focused_error_border(focused_error_border())
18509                };
18510                for decoration in [with_text as fn() -> InputDecoration, with_widget] {
18511                    M2::new(decoration()).is_focused(true).pump(tester);
18512                    tester.pump_and_settle(); // Border changes are animated.
18513                    assert!(*get_border(tester).unwrap() == *focused_error_border());
18514
18515                    M2::new(decoration()).pump(tester);
18516                    tester.pump_and_settle(); // Border changes are animated.
18517                    assert!(*get_border(tester).unwrap() == *error_border());
18518
18519                    M2::new(decoration().enabled(false)).pump(tester);
18520                    tester.pump_and_settle(); // Border changes are animated.
18521                    assert!(*get_border(tester).unwrap() == *error_border());
18522                }
18523            });
18524        }
18525
18526        // input_decorator_test.dart 'Material2 - InputDecorator prefix/suffix texts'.
18527        #[test]
18528        fn material2_prefix_and_suffix_texts() {
18529            test_widgets(|tester| {
18530                M2::new(
18531                    InputDecoration::new()
18532                        .prefix_text("p")
18533                        .suffix_text("s")
18534                        .filled(true),
18535                )
18536                .pump(tester);
18537
18538                // The prefix and suffix wrap the input text and are left and right justified
18539                // respectively. They should have the same height as the input text (16).
18540                assert_eq!(
18541                    decorator_size(tester),
18542                    Size::new(800.0, K_MIN_INTERACTIVE_DIMENSION)
18543                );
18544                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 16.0);
18545                assert_eq!(tester.get_rect(find::text("p")).height(), 16.0);
18546                assert_eq!(tester.get_rect(find::text("s")).height(), 16.0);
18547                assert_eq!(top(tester, INPUT_TEXT), 16.0);
18548                assert_eq!(top(tester, "p"), 16.0);
18549                assert_eq!(tester.get_rect(find::text("p")).left, 12.0);
18550                assert_eq!(top(tester, "s"), 16.0);
18551                assert_eq!(tester.get_rect(find::text("s")).right, 788.0);
18552
18553                // layout is a row: [p text s]
18554                assert_eq!(tester.get_rect(find::text("p")).left, 12.0);
18555                assert!(
18556                    tester.get_rect(find::text("p")).right
18557                        <= tester.get_rect(find::text(INPUT_TEXT)).left
18558                );
18559                assert!(
18560                    tester.get_rect(find::text(INPUT_TEXT)).right
18561                        <= tester.get_rect(find::text("s")).left
18562                );
18563            });
18564        }
18565
18566        // input_decorator_test.dart 'Material2 - InputDecorator icon/prefix/suffix'.
18567        #[test]
18568        fn material2_icon_prefix_and_suffix() {
18569            test_widgets(|tester| {
18570                M2::new(
18571                    InputDecoration::new()
18572                        .prefix_text("p")
18573                        .suffix_text("s")
18574                        .icon(Icon::new(Some(Icons::android())))
18575                        .filled(true),
18576                )
18577                .pump(tester);
18578
18579                assert_eq!(
18580                    decorator_size(tester),
18581                    Size::new(800.0, K_MIN_INTERACTIVE_DIMENSION)
18582                );
18583                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 16.0);
18584                assert_eq!(tester.get_rect(find::text("p")).height(), 16.0);
18585                assert_eq!(tester.get_rect(find::text("s")).height(), 16.0);
18586                assert_eq!(top(tester, INPUT_TEXT), 16.0);
18587                assert_eq!(top(tester, "p"), 16.0);
18588                assert_eq!(top(tester, "s"), 16.0);
18589                assert_eq!(tester.get_rect(find::text("s")).right, 788.0);
18590                let icon = icon_rect(tester, &Icons::android());
18591                assert_eq!(icon.height(), 24.0);
18592
18593                // The 24dps high icon is centered on the 16dps high input line
18594                assert_eq!(icon.top, 12.0);
18595
18596                // layout is a row: [icon, p text s]
18597                assert_eq!(icon.left, 0.0);
18598                assert!(icon.right <= tester.get_rect(find::text("p")).left);
18599                assert!(
18600                    tester.get_rect(find::text("p")).right
18601                        <= tester.get_rect(find::text(INPUT_TEXT)).left
18602                );
18603                assert!(
18604                    tester.get_rect(find::text(INPUT_TEXT)).right
18605                        <= tester.get_rect(find::text("s")).left
18606                );
18607            });
18608        }
18609
18610        // input_decorator_test.dart 'Material2 - InputDecorator prefix/suffix widgets'.
18611        #[test]
18612        fn material2_prefix_and_suffix_widgets() {
18613            test_widgets(|tester| {
18614                let p_key = GlobalKey::new();
18615                let s_key = GlobalKey::new();
18616                M2::new(
18617                    InputDecoration::new()
18618                        .prefix(
18619                            Padding::new(EdgeInsetsGeometry::all(4.0))
18620                                .key(p_key.clone().into())
18621                                .child(Text::new("p")),
18622                        )
18623                        .suffix(
18624                            Padding::new(EdgeInsetsGeometry::all(4.0))
18625                                .key(s_key.clone().into())
18626                                .child(Text::new("s")),
18627                        )
18628                        .filled(true),
18629                )
18630                .pump(tester);
18631
18632                // Overall height for this InputDecorator is 48dps because
18633                // the prefix and the suffix widget is surrounded with padding:
18634                //   12 - top padding
18635                //    4 - top prefix/suffix padding
18636                //   16 - input text (font size 16dps)
18637                //    4 - bottom prefix/suffix padding
18638                //   12 - bottom padding
18639                assert_eq!(decorator_size(tester), Size::new(800.0, 48.0));
18640                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 16.0);
18641                assert_eq!(key_rect(tester, &p_key).height(), 24.0);
18642                assert_eq!(tester.get_rect(find::text("p")).height(), 16.0);
18643                assert_eq!(key_rect(tester, &s_key).height(), 24.0);
18644                assert_eq!(tester.get_rect(find::text("s")).height(), 16.0);
18645                assert_eq!(top(tester, INPUT_TEXT), 16.0);
18646                assert_eq!(key_rect(tester, &p_key).top, 12.0);
18647                assert_eq!(top(tester, "p"), 16.0);
18648                assert_eq!(key_rect(tester, &s_key).top, 12.0);
18649                assert_eq!(top(tester, "s"), 16.0);
18650                assert_eq!(key_rect(tester, &s_key).right, 788.0);
18651                assert_eq!(tester.get_rect(find::text("s")).right, 784.0);
18652
18653                // layout is a row: [prefix text suffix]
18654                assert_eq!(key_rect(tester, &p_key).left, 12.0);
18655                assert_eq!(
18656                    key_rect(tester, &p_key).right,
18657                    tester.get_rect(find::text(INPUT_TEXT)).left
18658                );
18659                assert!(
18660                    tester.get_rect(find::text(INPUT_TEXT)).right <= key_rect(tester, &s_key).right
18661                );
18662            });
18663        }
18664
18665        // input_decorator_test.dart 'Material2 - InputDecorator tall prefix'.
18666        #[test]
18667        fn material2_tall_prefix() {
18668            test_widgets(|tester| {
18669                let p_key = GlobalKey::new();
18670                M2::new(
18671                    InputDecoration::new()
18672                        .prefix(sized(&p_key, 10.0, 100.0))
18673                        .filled(true),
18674                )
18675                // Set the fontSize so that everything works out to whole numbers.
18676                .child(
18677                    Text::new(INPUT_TEXT)
18678                        .style(TextStyle::new().font_size(20.0))
18679                        .into_widget(),
18680                )
18681                .pump(tester);
18682
18683                assert_eq!(decorator_size(tester).width(), 800.0);
18684                assert_eq!(decorator_size(tester).height(), 129.0);
18685                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 20.0);
18686                assert_eq!(key_rect(tester, &p_key).height(), 100.0);
18687                assert_eq!(top(tester, INPUT_TEXT), 97.0); // 12 + 100 - 15
18688                assert_eq!(key_rect(tester, &p_key).top, 12.0);
18689
18690                // layout is a row: [prefix text suffix]
18691                assert_eq!(key_rect(tester, &p_key).left, 12.0);
18692                assert_eq!(
18693                    key_rect(tester, &p_key).right,
18694                    tester.get_rect(find::text(INPUT_TEXT)).left
18695                );
18696            });
18697        }
18698
18699        // input_decorator_test.dart 'Material2 - InputDecorator tall prefix with border'.
18700        #[test]
18701        fn material2_tall_prefix_with_border() {
18702            test_widgets(|tester| {
18703                let p_key = GlobalKey::new();
18704                M2::new(
18705                    InputDecoration::new()
18706                        .border(OutlineInputBorder::new())
18707                        .prefix(sized(&p_key, 10.0, 100.0))
18708                        .filled(true),
18709                )
18710                // Set the fontSize so that everything works out to whole numbers.
18711                .child(
18712                    Text::new(INPUT_TEXT)
18713                        .style(TextStyle::new().font_size(20.0))
18714                        .into_widget(),
18715                )
18716                .pump(tester);
18717
18718                // When a border is present, the input text and prefix/suffix are centered
18719                // within the input. Here, that will be content of height 106, centered
18720                // within an input of height 145. That gives 20 pixels of space on each side
18721                // of the content, so the prefix is positioned at 19, and the text is at
18722                // 20+100-15=105.
18723                assert_eq!(decorator_size(tester).width(), 800.0);
18724                assert_eq!(decorator_size(tester).height(), 145.0);
18725                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 20.0);
18726                assert_eq!(key_rect(tester, &p_key).height(), 100.0);
18727                assert_eq!(top(tester, INPUT_TEXT), 105.0);
18728                assert_eq!(key_rect(tester, &p_key).top, 20.0);
18729
18730                // layout is a row: [prefix text suffix]
18731                assert_eq!(key_rect(tester, &p_key).left, 12.0);
18732                assert_eq!(
18733                    key_rect(tester, &p_key).right,
18734                    tester.get_rect(find::text(INPUT_TEXT)).left
18735                );
18736            });
18737        }
18738
18739        // input_decorator_test.dart 'Material2 - InputDecorator prefixIcon/suffixIcon'.
18740        #[test]
18741        fn material2_prefix_icon_and_suffix_icon() {
18742            test_widgets(|tester| {
18743                M2::new(
18744                    InputDecoration::new()
18745                        .prefix_icon(Icon::new(Some(Icons::pages())))
18746                        .suffix_icon(Icon::new(Some(Icons::satellite())))
18747                        .filled(true),
18748                )
18749                .pump(tester);
18750
18751                // Overall height for this InputDecorator is 48dps because the prefix icon's minimum
18752                // size is 48x48 and the rest of the elements only require 40dps.
18753                assert_eq!(decorator_size(tester), Size::new(800.0, 48.0));
18754                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 16.0);
18755                let pages = icon_rect(tester, &Icons::pages());
18756                let satellite = icon_rect(tester, &Icons::satellite());
18757                assert_eq!(pages.height(), 48.0);
18758                assert_eq!(satellite.height(), 48.0);
18759                assert_eq!(top(tester, INPUT_TEXT), 12.0);
18760                assert_eq!(pages.top, 0.0);
18761                assert_eq!(satellite.top, 0.0);
18762                assert_eq!(satellite.right, 800.0);
18763
18764                // layout is a row: [icon text icon]
18765                assert_eq!(pages.left, 0.0);
18766                assert!(pages.right <= tester.get_rect(find::text(INPUT_TEXT)).left);
18767                assert!(tester.get_rect(find::text(INPUT_TEXT)).right <= satellite.left);
18768            });
18769        }
18770
18771        // input_decorator_test.dart 'Material2 - InputDecorator
18772        // prefixIconConstraints/suffixIconConstraints'.
18773        #[test]
18774        fn material2_prefix_icon_and_suffix_icon_constraints() {
18775            test_widgets(|tester| {
18776                M2::new(
18777                    InputDecoration::new()
18778                        .prefix_icon(Icon::new(Some(Icons::pages())))
18779                        .prefix_icon_constraints(BoxConstraints {
18780                            min_width: 32.0,
18781                            min_height: 32.0,
18782                            ..BoxConstraints::new()
18783                        })
18784                        .suffix_icon(Icon::new(Some(Icons::satellite())))
18785                        .suffix_icon_constraints(BoxConstraints {
18786                            min_width: 25.0,
18787                            min_height: 25.0,
18788                            ..BoxConstraints::new()
18789                        })
18790                        .is_dense(true), // has to be true to go below 48px height
18791                )
18792                .pump(tester);
18793
18794                // Overall height for this InputDecorator is 32px because the prefix icon
18795                // is now a custom value
18796                assert_eq!(decorator_size(tester), Size::new(800.0, 32.0));
18797                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 16.0);
18798                let pages = icon_rect(tester, &Icons::pages());
18799                let satellite = icon_rect(tester, &Icons::satellite());
18800                assert_eq!(pages.height(), 32.0);
18801                assert_eq!(satellite.height(), 25.0);
18802
18803                // (InputDecorator height - Text widget height) / 2
18804                assert_eq!(top(tester, INPUT_TEXT), (32.0 - 16.0) / 2.0);
18805                // prefixIcon should take up the entire height of InputDecorator
18806                assert_eq!(pages.top, 0.0);
18807                // (InputDecorator height - suffixIcon height) / 2
18808                assert_eq!(satellite.top, (32.0 - 25.0) / 2.0);
18809                assert_eq!(satellite.right, 800.0);
18810            });
18811        }
18812
18813        // input_decorator_test.dart 'Material2 - prefix/suffix icons are centered when smaller than
18814        // 48 by 48'.
18815        #[test]
18816        fn material2_prefix_and_suffix_icons_are_centered_when_smaller_than_48_by_48() {
18817            test_widgets(|tester| {
18818                let prefix_key = GlobalKey::new();
18819                M2::new(
18820                    InputDecoration::new()
18821                        .prefix_icon(Padding::new(EdgeInsetsGeometry::all(16.0)).child(sized(
18822                            &prefix_key,
18823                            8.0,
18824                            8.0,
18825                        )))
18826                        .filled(true),
18827                )
18828                .pump(tester);
18829
18830                assert_eq!(decorator_size(tester), Size::new(800.0, 48.0));
18831                assert_eq!(key_rect(tester, &prefix_key).height(), 16.0);
18832                assert_eq!(key_rect(tester, &prefix_key).top, 16.0);
18833            });
18834        }
18835
18836        /// The shared steps of the two visual density cases: Dart's expected positions for the
18837        /// unfocused and the focused field, with `base` the decorator height.
18838        struct DensityFrame {
18839            height: f64,
18840            input_top: f64,
18841            label_top: f64,
18842            floating_label_top: f64,
18843        }
18844
18845        fn check_visual_density(
18846            tester: &mut WidgetTester,
18847            density: VisualDensity,
18848            frame: DensityFrame,
18849        ) {
18850            let build = |is_empty: bool, is_focused: bool| {
18851                M2::new(label_and_hint())
18852                    .is_empty(is_empty)
18853                    .is_focused(is_focused)
18854                    .visual_density(density)
18855            };
18856            // Label is visible, hint is not (opacity 0.0).
18857            build(true, false).pump(tester);
18858
18859            // The label is not floating so it's vertically centered.
18860            assert_eq!(decorator_size(tester), Size::new(800.0, frame.height));
18861            assert_eq!(top(tester, INPUT_TEXT), frame.input_top);
18862            assert_eq!(bottom(tester, INPUT_TEXT), frame.input_top + 16.0);
18863            assert_eq!(top(tester, LABEL_TEXT), frame.label_top);
18864            assert_eq!(bottom(tester, LABEL_TEXT), frame.label_top + 16.0);
18865            assert_eq!(get_opacity(tester, HINT_TEXT), 0.0);
18866            assert_eq!(get_border_bottom(tester), frame.height);
18867            assert_eq!(get_border_weight(tester), 1.0);
18868
18869            // Label moves upwards, hint is visible (opacity 1.0).
18870            build(true, true).pump(tester);
18871
18872            // The hint's opacity animates from 0.0 to 1.0.
18873            // The animation's default duration is 20ms.
18874            tester.pump_by(Duration::from_millis(9));
18875            let hint_opacity_9ms = get_opacity(tester, HINT_TEXT);
18876            assert!(in_exclusive_range(hint_opacity_9ms, 0.0, 1.0));
18877            tester.pump_by(Duration::from_millis(9));
18878            let hint_opacity_18ms = get_opacity(tester, HINT_TEXT);
18879            assert!(in_exclusive_range(hint_opacity_18ms, hint_opacity_9ms, 1.0));
18880
18881            tester.pump_and_settle();
18882            let check_focused = |tester: &WidgetTester, hint_opacity: f64| {
18883                assert_eq!(decorator_size(tester), Size::new(800.0, frame.height));
18884                assert_eq!(top(tester, INPUT_TEXT), frame.input_top);
18885                assert_eq!(bottom(tester, INPUT_TEXT), frame.input_top + 16.0);
18886                assert_eq!(top(tester, LABEL_TEXT), frame.floating_label_top);
18887                assert_eq!(bottom(tester, LABEL_TEXT), frame.floating_label_top + 12.0);
18888                assert_eq!(top(tester, HINT_TEXT), frame.input_top);
18889                assert_eq!(bottom(tester, HINT_TEXT), frame.input_top + 16.0);
18890                assert_eq!(get_opacity(tester, HINT_TEXT), hint_opacity);
18891                assert_eq!(get_border_bottom(tester), frame.height);
18892                assert_eq!(get_border_weight(tester), 2.0);
18893            };
18894            check_focused(tester, 1.0);
18895
18896            build(false, true).pump(tester);
18897
18898            // The hint's opacity animates from 1.0 to 0.0.
18899            // The animation's default duration is 20ms.
18900            tester.pump_by(Duration::from_millis(9));
18901            let hint_opacity_9ms = get_opacity(tester, HINT_TEXT);
18902            assert!(in_exclusive_range(hint_opacity_9ms, 0.0, 1.0));
18903            tester.pump_by(Duration::from_millis(9));
18904            let hint_opacity_18ms = get_opacity(tester, HINT_TEXT);
18905            assert!(in_exclusive_range(hint_opacity_18ms, 0.0, hint_opacity_9ms));
18906
18907            tester.pump_and_settle();
18908            check_focused(tester, 0.0);
18909        }
18910
18911        // input_decorator_test.dart 'Material2 - InputDecorator respects reduced theme visualDensity'.
18912        #[test]
18913        fn material2_decorator_respects_reduced_theme_visual_density() {
18914            test_widgets(|tester| {
18915                check_visual_density(
18916                    tester,
18917                    VisualDensity::COMPACT,
18918                    DensityFrame {
18919                        height: 48.0,
18920                        input_top: 24.0,
18921                        label_top: 16.0,
18922                        floating_label_top: 8.0,
18923                    },
18924                );
18925            });
18926        }
18927
18928        // input_decorator_test.dart 'Material2 - InputDecorator respects increased theme
18929        // visualDensity'.
18930        #[test]
18931        fn material2_decorator_respects_increased_theme_visual_density() {
18932            test_widgets(|tester| {
18933                check_visual_density(
18934                    tester,
18935                    VisualDensity::new(2.0, 2.0),
18936                    DensityFrame {
18937                        height: 64.0,
18938                        input_top: 32.0,
18939                        label_top: 24.0,
18940                        floating_label_top: 16.0,
18941                    },
18942                );
18943            });
18944        }
18945
18946        // input_decorator_test.dart 'Material2 - prefix/suffix icons increase height of decoration
18947        // when larger than 48 by 48'.
18948        #[test]
18949        fn material2_prefix_and_suffix_icons_increase_height_when_larger_than_48_by_48() {
18950            test_widgets(|tester| {
18951                let prefix_key = GlobalKey::new();
18952                M2::new(
18953                    InputDecoration::new()
18954                        .prefix_icon(sized(&prefix_key, 100.0, 100.0))
18955                        .filled(true),
18956                )
18957                .pump(tester);
18958
18959                assert_eq!(decorator_size(tester), Size::new(800.0, 100.0));
18960                assert_eq!(key_rect(tester, &prefix_key).height(), 100.0);
18961                assert_eq!(key_rect(tester, &prefix_key).top, 0.0);
18962            });
18963        }
18964
18965        // input_decorator_test.dart 'Material2 - constraints - No InputDecorator constraints'.
18966        #[test]
18967        fn material2_no_constraints_fill_the_width_at_the_default_height() {
18968            test_widgets(|tester| {
18969                M2::new(InputDecoration::new()).pump(tester);
18970
18971                // Should fill the screen width and be default height
18972                assert_eq!(decorator_size(tester), Size::new(800.0, 48.0));
18973            });
18974        }
18975
18976        fn theme_with_constraints(app: &App) -> ThemeData {
18977            ThemeData::builder()
18978                .input_decoration_theme(InputDecorationThemeData::new().constraints(
18979                    BoxConstraints {
18980                        max_width: 300.0,
18981                        max_height: 40.0,
18982                        ..BoxConstraints::new()
18983                    },
18984                ))
18985                .build(app)
18986        }
18987
18988        // input_decorator_test.dart 'Material2 - constraints - InputDecoratorThemeData constraints'.
18989        #[test]
18990        fn material2_theme_constraints_size_the_decorator() {
18991            test_widgets(|tester| {
18992                M2::new(InputDecoration::new())
18993                    .theme(theme_with_constraints)
18994                    .pump(tester);
18995
18996                // Theme settings should make it 300x40 pixels
18997                assert_eq!(decorator_size(tester), Size::new(300.0, 40.0));
18998            });
18999        }
19000
19001        // input_decorator_test.dart 'Material2 - constraints - InputDecorator constraints'.
19002        #[test]
19003        fn material2_decoration_constraints_override_the_theme() {
19004            test_widgets(|tester| {
19005                M2::new(InputDecoration::new().constraints(BoxConstraints {
19006                    max_width: 200.0,
19007                    max_height: 32.0,
19008                    ..BoxConstraints::new()
19009                }))
19010                .theme(theme_with_constraints)
19011                .pump(tester);
19012
19013                // InputDecoration.constraints should override the theme. It should be
19014                // only 200x32 pixels
19015                assert_eq!(decorator_size(tester), Size::new(200.0, 32.0));
19016            });
19017        }
19018
19019        /// Dart's `Text(text, style: TextStyle(fontFamily: 'FlutterTest', fontSize: 20.0))`, set so
19020        /// that everything works out to whole numbers.
19021        fn text_20() -> WidgetRef {
19022            Text::new(INPUT_TEXT)
19023                .style(TextStyle::new().font_size(20.0))
19024                .into_widget()
19025        }
19026
19027        /// The input's top in an expanded Material 2 decorator with `decoration` aligned by
19028        /// `align`: the cases of 'textAlignVertical position'.
19029        fn expanded_input_top(
19030            tester: &mut WidgetTester,
19031            decoration: InputDecoration,
19032            align: TextAlignVertical,
19033        ) -> f64 {
19034            M2::new(decoration)
19035                .expands(true) // so we have a tall input where align can vary
19036                .text_align_vertical(align)
19037                .child(text_20())
19038                .pump(tester);
19039            top(tester, INPUT_TEXT)
19040        }
19041
19042        // input_decorator_test.dart 'Material2 - textAlignVertical position - simple case - align
19043        // top (default)'.
19044        #[test]
19045        fn material2_text_align_vertical_top_puts_the_input_at_the_top() {
19046            test_widgets(|tester| {
19047                // Same as the default case above.
19048                assert_eq!(
19049                    expanded_input_top(
19050                        tester,
19051                        InputDecoration::new().filled(true),
19052                        TextAlignVertical::TOP
19053                    ),
19054                    12.0
19055                );
19056            });
19057        }
19058
19059        // input_decorator_test.dart 'Material2 - textAlignVertical position - simple case - align
19060        // center'.
19061        #[test]
19062        fn material2_text_align_vertical_center_centers_the_input() {
19063            test_widgets(|tester| {
19064                // Below the top aligned case.
19065                assert_eq!(
19066                    expanded_input_top(
19067                        tester,
19068                        InputDecoration::new().filled(true),
19069                        TextAlignVertical::CENTER
19070                    ),
19071                    290.0
19072                );
19073            });
19074        }
19075
19076        // input_decorator_test.dart 'Material2 - textAlignVertical position - simple case - align
19077        // bottom'.
19078        #[test]
19079        fn material2_text_align_vertical_bottom_puts_the_input_at_the_bottom() {
19080            test_widgets(|tester| {
19081                // Below the center aligned case.
19082                assert_eq!(
19083                    expanded_input_top(
19084                        tester,
19085                        InputDecoration::new().filled(true),
19086                        TextAlignVertical::BOTTOM
19087                    ),
19088                    568.0
19089                );
19090            });
19091        }
19092
19093        // input_decorator_test.dart 'Material2 - textAlignVertical position - simple case - align
19094        // as a double'.
19095        #[test]
19096        fn material2_text_align_vertical_as_a_double_interpolates() {
19097            test_widgets(|tester| {
19098                // In between the center and bottom aligned cases.
19099                assert_eq!(
19100                    expanded_input_top(
19101                        tester,
19102                        InputDecoration::new().filled(true),
19103                        TextAlignVertical::new(0.75)
19104                    ),
19105                    498.5
19106                );
19107            });
19108        }
19109
19110        // input_decorator_test.dart 'Material2 - textAlignVertical position - simple case - works
19111        // with density and content padding'.
19112        #[test]
19113        fn material2_text_align_vertical_works_with_density_and_content_padding() {
19114            test_widgets(|tester| {
19115                let key = GlobalKey::new();
19116                let container_key = GlobalKey::new();
19117                const TOTAL_HEIGHT: f64 = 100.0;
19118                const CHILD_HEIGHT: f64 = 20.0;
19119                let visual_density = VisualDensity::new(0.0, VisualDensity::MAXIMUM_DENSITY);
19120                let content_padding = EdgeInsets::only(0.0, 6.0, 0.0, 14.0);
19121
19122                let decorator = M2::new(
19123                    InputDecoration::new()
19124                        .border(InputBorderRef::none())
19125                        .content_padding(EdgeInsetsGeometry::from(content_padding)),
19126                )
19127                .expands(true)
19128                .text_align_vertical(TextAlignVertical::CENTER)
19129                .visual_density(visual_density)
19130                .child(SizedBox::new().key(key.clone().into()).height(CHILD_HEIGHT))
19131                .build(tester);
19132                tester.pump_widget(
19133                    waft_widgets::Center::new()
19134                        .child(
19135                            SizedBox::new()
19136                                .key(container_key.clone().into())
19137                                .height(TOTAL_HEIGHT)
19138                                .child(decorator),
19139                        )
19140                        .into_widget(),
19141                );
19142
19143                // Vertical components: contentPadding.vertical, densityOffset.y, child
19144                let density_dy = visual_density.base_size_adjustment().dy();
19145                let child_vertical_space_affordance =
19146                    TOTAL_HEIGHT - density_dy - content_padding.vertical();
19147
19148                // TextAlignVertical.center is specified so `child` needs to be centered
19149                // in the available space.
19150                let child_margin = (child_vertical_space_affordance - CHILD_HEIGHT) / 2.0;
19151                let child_top = density_dy / 2.0 + content_padding.top + child_margin;
19152
19153                assert_eq!(
19154                    key_rect(tester, &key).top,
19155                    key_rect(tester, &container_key).top + child_top
19156                );
19157            });
19158        }
19159
19160        fn filled_outline() -> InputDecoration {
19161            InputDecoration::new()
19162                .filled(true)
19163                .border(OutlineInputBorder::new())
19164        }
19165
19166        // input_decorator_test.dart 'Material2 - textAlignVertical position - outline border -
19167        // align top'.
19168        #[test]
19169        fn material2_outline_text_align_vertical_top_leaves_room_for_the_border() {
19170            test_widgets(|tester| {
19171                // Similar to the case without a border, but with a little extra room at
19172                // the top to make room for the border.
19173                assert_eq!(
19174                    expanded_input_top(tester, filled_outline(), TextAlignVertical::TOP),
19175                    24.0
19176                );
19177            });
19178        }
19179
19180        // input_decorator_test.dart 'Material2 - textAlignVertical position - outline border -
19181        // align center (default)'.
19182        #[test]
19183        fn material2_outline_text_align_vertical_center_centers_the_input() {
19184            test_widgets(|tester| {
19185                // Below the top aligned case.
19186                assert_eq!(
19187                    expanded_input_top(tester, filled_outline(), TextAlignVertical::CENTER),
19188                    290.0
19189                );
19190            });
19191        }
19192
19193        // input_decorator_test.dart 'Material2 - textAlignVertical position - outline border -
19194        // align bottom'.
19195        #[test]
19196        fn material2_outline_text_align_vertical_bottom_puts_the_input_at_the_bottom() {
19197            test_widgets(|tester| {
19198                // Below the center aligned case.
19199                assert_eq!(
19200                    expanded_input_top(tester, filled_outline(), TextAlignVertical::BOTTOM),
19201                    564.0
19202                );
19203            });
19204        }
19205
19206        /// The input's and the prefix's tops for a tall prefix, under `align`, in an expanded
19207        /// decorator when `expands`.
19208        fn tall_prefix_tops(
19209            tester: &mut WidgetTester,
19210            outline: bool,
19211            expands: bool,
19212            align: TextAlignVertical,
19213        ) -> (f64, f64) {
19214            let p_key = GlobalKey::new();
19215            let mut decoration = InputDecoration::new()
19216                .prefix(sized(&p_key, 10.0, 100.0))
19217                .filled(true);
19218            if outline {
19219                decoration = decoration.border(OutlineInputBorder::new());
19220            }
19221            M2::new(decoration)
19222                .expands(expands)
19223                .text_align_vertical(align)
19224                .child(text_20())
19225                .pump(tester);
19226            (top(tester, INPUT_TEXT), key_rect(tester, &p_key).top)
19227        }
19228
19229        // input_decorator_test.dart 'Material2 - textAlignVertical position - prefix - InputDecorator
19230        // tall prefix align top'.
19231        #[test]
19232        fn material2_tall_prefix_align_top() {
19233            test_widgets(|tester| {
19234                // Same as the default case above.
19235                assert_eq!(
19236                    tall_prefix_tops(tester, false, false, TextAlignVertical::TOP),
19237                    (97.0, 12.0)
19238                );
19239            });
19240        }
19241
19242        // input_decorator_test.dart 'Material2 - textAlignVertical position - prefix - InputDecorator
19243        // tall prefix align center'.
19244        #[test]
19245        fn material2_tall_prefix_align_center() {
19246            test_widgets(|tester| {
19247                // Same as the default case above.
19248                assert_eq!(
19249                    tall_prefix_tops(tester, false, false, TextAlignVertical::CENTER),
19250                    (97.0, 12.0)
19251                );
19252            });
19253        }
19254
19255        // input_decorator_test.dart 'Material2 - textAlignVertical position - prefix - InputDecorator
19256        // tall prefix align bottom'.
19257        #[test]
19258        fn material2_tall_prefix_align_bottom() {
19259            test_widgets(|tester| {
19260                // Top of the input + 100 prefix height - overlap
19261                assert_eq!(
19262                    tall_prefix_tops(tester, false, false, TextAlignVertical::BOTTOM),
19263                    (97.0, 12.0)
19264                );
19265            });
19266        }
19267
19268        // input_decorator_test.dart 'Material2 - textAlignVertical position - outline border and
19269        // prefix - InputDecorator tall prefix align center'.
19270        #[test]
19271        fn material2_outline_tall_prefix_align_center() {
19272            test_widgets(|tester| {
19273                // In the middle of the expanded InputDecorator.
19274                assert_eq!(
19275                    tall_prefix_tops(tester, true, true, TextAlignVertical::CENTER),
19276                    (332.5, 247.5)
19277                );
19278            });
19279        }
19280
19281        // input_decorator_test.dart 'Material2 - textAlignVertical position - outline border and
19282        // prefix - InputDecorator tall prefix with border align top'.
19283        #[test]
19284        fn material2_outline_tall_prefix_align_top() {
19285            test_widgets(|tester| {
19286                // Above the center example; the prefix is positioned at the top of the input, so
19287                // its value is the same as the top aligned test without a prefix.
19288                assert_eq!(
19289                    tall_prefix_tops(tester, true, true, TextAlignVertical::TOP),
19290                    (109.0, 24.0)
19291                );
19292            });
19293        }
19294
19295        // input_decorator_test.dart 'Material2 - textAlignVertical position - outline border and
19296        // prefix - InputDecorator tall prefix with border align bottom'.
19297        #[test]
19298        fn material2_outline_tall_prefix_align_bottom() {
19299            test_widgets(|tester| {
19300                // Below the center example.
19301                assert_eq!(
19302                    tall_prefix_tops(tester, true, true, TextAlignVertical::BOTTOM),
19303                    (564.0, 479.0)
19304                );
19305            });
19306        }
19307
19308        // input_decorator_test.dart 'Material2 - textAlignVertical position - outline border and
19309        // prefix - InputDecorator tall prefix with border align double'.
19310        #[test]
19311        fn material2_outline_tall_prefix_align_double() {
19312            test_widgets(|tester| {
19313                // Between the top and center examples.
19314                let (input_top, prefix_top) =
19315                    tall_prefix_tops(tester, true, true, TextAlignVertical::new(0.1));
19316                // Waft's `Matrix4` is f32, so a position read through `local_to_global` keeps f32
19317                // precision where Dart's is a double.
19318                assert_f32_equals(input_top, 355.65);
19319                assert_f32_equals(prefix_top, 270.65);
19320            });
19321        }
19322
19323        fn filled_with_label() -> InputDecoration {
19324            InputDecoration::new().label_text(LABEL_TEXT).filled(true)
19325        }
19326
19327        // input_decorator_test.dart 'Material2 - textAlignVertical position - label - align top
19328        // (default)'.
19329        #[test]
19330        fn material2_label_text_align_vertical_top_starts_the_input_lower() {
19331            test_widgets(|tester| {
19332                // The label causes the text to start slightly lower than it would
19333                // otherwise.
19334                assert_eq!(
19335                    expanded_input_top(tester, filled_with_label(), TextAlignVertical::TOP),
19336                    28.0
19337                );
19338            });
19339        }
19340
19341        // input_decorator_test.dart 'Material2 - textAlignVertical position - label - align center'.
19342        #[test]
19343        fn material2_label_text_align_vertical_center_is_slightly_lower() {
19344            test_widgets(|tester| {
19345                // The label reduces the amount of space available for text, so the
19346                // center is slightly lower.
19347                assert_eq!(
19348                    expanded_input_top(tester, filled_with_label(), TextAlignVertical::CENTER),
19349                    298.0
19350                );
19351            });
19352        }
19353
19354        // input_decorator_test.dart 'Material2 - textAlignVertical position - label - align bottom'.
19355        #[test]
19356        fn material2_label_text_align_vertical_bottom_keeps_the_bottom_line() {
19357            test_widgets(|tester| {
19358                // The label reduces the amount of space available for text, but the
19359                // bottom line is still in the same place.
19360                assert_eq!(
19361                    expanded_input_top(tester, filled_with_label(), TextAlignVertical::BOTTOM),
19362                    568.0
19363                );
19364            });
19365        }
19366
19367        /// The decorator's size and the input's top and bottom for `decoration`, with Dart's
19368        /// border bottom and weight checked alongside.
19369        fn check_outline_alignment(
19370            tester: &mut WidgetTester,
19371            decoration: InputDecoration,
19372            size: Size,
19373            input_top: f64,
19374            border_weight: f64,
19375        ) {
19376            M2::new(decoration).pump(tester);
19377            assert_eq!(decorator_size(tester), size);
19378            assert_eq!(top(tester, INPUT_TEXT), input_top);
19379            assert_eq!(bottom(tester, INPUT_TEXT), input_top + 16.0);
19380            assert_eq!(get_border_bottom(tester), size.height());
19381            assert_eq!(get_border_weight(tester), border_weight);
19382        }
19383
19384        // input_decorator_test.dart 'Material2 - OutlineInputBorder - default alignment - Centers
19385        // when border'.
19386        #[test]
19387        fn material2_outline_centers_the_input() {
19388            test_widgets(|tester| {
19389                check_outline_alignment(
19390                    tester,
19391                    InputDecoration::new().border(OutlineInputBorder::new()),
19392                    Size::new(800.0, 56.0),
19393                    20.0,
19394                    1.0,
19395                );
19396            });
19397        }
19398
19399        // input_decorator_test.dart 'Material2 - OutlineInputBorder - default alignment - Centers
19400        // when border and label'.
19401        #[test]
19402        fn material2_outline_with_a_label_centers_the_input() {
19403            test_widgets(|tester| {
19404                check_outline_alignment(
19405                    tester,
19406                    InputDecoration::new()
19407                        .label_text(LABEL_TEXT)
19408                        .border(OutlineInputBorder::new()),
19409                    Size::new(800.0, 56.0),
19410                    20.0,
19411                    1.0,
19412                );
19413            });
19414        }
19415
19416        // input_decorator_test.dart 'Material2 - OutlineInputBorder - default alignment - Centers
19417        // when border and contentPadding'.
19418        #[test]
19419        fn material2_outline_with_content_padding_centers_the_input() {
19420            test_widgets(|tester| {
19421                check_outline_alignment(
19422                    tester,
19423                    InputDecoration::new()
19424                        .border(OutlineInputBorder::new())
19425                        .content_padding(EdgeInsetsGeometry::from(EdgeInsets::from_ltrb(
19426                            12.0, 14.0, 8.0, 14.0,
19427                        ))),
19428                    Size::new(800.0, 48.0),
19429                    16.0,
19430                    1.0,
19431                );
19432            });
19433        }
19434
19435        // input_decorator_test.dart 'Material2 - OutlineInputBorder - default alignment - Centers
19436        // when border and contentPadding and label'.
19437        #[test]
19438        fn material2_outline_with_content_padding_and_label_centers_the_input() {
19439            test_widgets(|tester| {
19440                check_outline_alignment(
19441                    tester,
19442                    InputDecoration::new()
19443                        .label_text(LABEL_TEXT)
19444                        .border(OutlineInputBorder::new())
19445                        .content_padding(EdgeInsetsGeometry::from(EdgeInsets::from_ltrb(
19446                            12.0, 14.0, 8.0, 14.0,
19447                        ))),
19448                    Size::new(800.0, K_MIN_INTERACTIVE_DIMENSION),
19449                    16.0,
19450                    1.0,
19451                );
19452            });
19453        }
19454
19455        // input_decorator_test.dart 'Material2 - OutlineInputBorder - default alignment - Centers
19456        // when border and lopsided contentPadding and label'.
19457        #[test]
19458        fn material2_outline_with_lopsided_content_padding_and_label_centers_the_input() {
19459            test_widgets(|tester| {
19460                check_outline_alignment(
19461                    tester,
19462                    InputDecoration::new()
19463                        .label_text(LABEL_TEXT)
19464                        .border(OutlineInputBorder::new())
19465                        .content_padding(EdgeInsetsGeometry::from(EdgeInsets::from_ltrb(
19466                            12.0, 104.0, 8.0, 0.0,
19467                        ))),
19468                    Size::new(800.0, 120.0),
19469                    52.0,
19470                    1.0,
19471                );
19472            });
19473        }
19474
19475        // input_decorator_test.dart 'Material2 - OutlineInputBorder - default alignment - Label
19476        // aligns horizontally with text'.
19477        #[test]
19478        fn material2_outline_label_aligns_horizontally_with_the_text() {
19479            test_widgets(|tester| {
19480                M2::new(
19481                    InputDecoration::new()
19482                        .prefix_icon(Icon::new(Some(Icons::ac_unit())))
19483                        .label_text(LABEL_TEXT)
19484                        .border(OutlineInputBorder::new()),
19485                )
19486                .is_focused(true)
19487                .pump(tester);
19488
19489                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
19490                assert_eq!(tester.get_rect(find::text(LABEL_TEXT)).left, 48.0);
19491                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).left, 48.0);
19492                assert_eq!(get_border_weight(tester), 2.0);
19493            });
19494        }
19495
19496        // input_decorator_test.dart 'Material2 - OutlineInputBorder - default alignment - Floating
19497        // label for filled input decoration is horizontally aligned with text'.
19498        #[test]
19499        fn material2_filled_floating_label_aligns_horizontally_with_the_text() {
19500            test_widgets(|tester| {
19501                M2::new(
19502                    InputDecoration::new()
19503                        .prefix_icon(Icon::new(Some(Icons::ac_unit())))
19504                        .label_text(LABEL_TEXT)
19505                        .filled(true),
19506                )
19507                .is_focused(true)
19508                .pump(tester);
19509
19510                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
19511                assert_eq!(tester.get_rect(find::text(LABEL_TEXT)).left, 48.0);
19512                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).left, 48.0);
19513                assert_eq!(get_border_weight(tester), 2.0);
19514            });
19515        }
19516
19517        /// The input's top and bottom in an expanded outlined decorator with `padding`, aligned by
19518        /// `align`: the '3 point interpolation alignment' cases.
19519        fn check_three_point(
19520            tester: &mut WidgetTester,
19521            align: TextAlignVertical,
19522            padding: EdgeInsets,
19523            input_top: f64,
19524        ) {
19525            M2::new(
19526                InputDecoration::new()
19527                    .border(OutlineInputBorder::new())
19528                    .content_padding(EdgeInsetsGeometry::from(padding)),
19529            )
19530            .expands(true)
19531            .text_align_vertical(align)
19532            .pump(tester);
19533
19534            assert_eq!(decorator_size(tester), Size::new(800.0, 600.0));
19535            assert_eq!(top(tester, INPUT_TEXT), input_top);
19536            assert_eq!(bottom(tester, INPUT_TEXT), input_top + 16.0);
19537            assert_eq!(get_border_bottom(tester), 600.0);
19538            assert_eq!(get_border_weight(tester), 1.0);
19539        }
19540
19541        // input_decorator_test.dart 'Material2 - OutlineInputBorder - 3 point interpolation
19542        // alignment - top align includes padding'.
19543        #[test]
19544        fn material2_three_point_top_align_includes_padding() {
19545            test_widgets(|tester| {
19546                // Aligned to the top including the 24px padding.
19547                check_three_point(
19548                    tester,
19549                    TextAlignVertical::TOP,
19550                    EdgeInsets::from_ltrb(12.0, 24.0, 8.0, 2.0),
19551                    24.0,
19552                );
19553            });
19554        }
19555
19556        // input_decorator_test.dart 'Material2 - OutlineInputBorder - 3 point interpolation
19557        // alignment - center align ignores padding'.
19558        #[test]
19559        fn material2_three_point_center_align_ignores_padding() {
19560            test_widgets(|tester| {
19561                // Baseline is on the center of the 600px high input.
19562                check_three_point(
19563                    tester,
19564                    TextAlignVertical::CENTER,
19565                    EdgeInsets::from_ltrb(12.0, 24.0, 8.0, 2.0),
19566                    292.0,
19567                );
19568            });
19569        }
19570
19571        // input_decorator_test.dart 'Material2 - OutlineInputBorder - 3 point interpolation
19572        // alignment - bottom align includes padding'.
19573        #[test]
19574        fn material2_three_point_bottom_align_includes_padding() {
19575            test_widgets(|tester| {
19576                // Includes bottom padding of 2px.
19577                check_three_point(
19578                    tester,
19579                    TextAlignVertical::BOTTOM,
19580                    EdgeInsets::from_ltrb(12.0, 24.0, 8.0, 2.0),
19581                    582.0,
19582                );
19583            });
19584        }
19585
19586        // input_decorator_test.dart 'Material2 - OutlineInputBorder - 3 point interpolation
19587        // alignment - padding exceeds middle keeps top at middle'.
19588        #[test]
19589        fn material2_three_point_padding_beyond_the_middle_keeps_the_top_at_the_middle() {
19590            test_widgets(|tester| {
19591                // Same position as the center example above.
19592                check_three_point(
19593                    tester,
19594                    TextAlignVertical::TOP,
19595                    EdgeInsets::from_ltrb(12.0, 504.0, 8.0, 0.0),
19596                    292.0,
19597                );
19598            });
19599        }
19600
19601        /// The decorator's size and the counter's rect for a filled decoration with a counter.
19602        fn counter_layout(
19603            tester: &mut WidgetTester,
19604            text_direction: TextDirection,
19605            is_dense: bool,
19606        ) -> (Size, Rect, Rect) {
19607            M2::new(
19608                InputDecoration::new()
19609                    .counter_text("test")
19610                    .filled(true)
19611                    .is_dense(is_dense),
19612            )
19613            .text_direction(text_direction)
19614            .pump(tester);
19615            (
19616                decorator_size(tester),
19617                get_decorator_rect(tester),
19618                tester.get_rect(find::text("test")),
19619            )
19620        }
19621
19622        // input_decorator_test.dart 'Material2 - counter text has correct right margin - LTR, not
19623        // dense'.
19624        #[test]
19625        fn material2_counter_right_margin_ltr_not_dense() {
19626            test_widgets(|tester| {
19627                // Margin for text decoration is 12 when filled
19628                // (dx) - 12 = (text offset)x.
19629                let (size, decorator, counter) = counter_layout(tester, TextDirection::Ltr, false);
19630                assert_eq!(size, Size::new(800.0, 68.0));
19631                assert_eq!(counter.right, decorator.right - 12.0);
19632            });
19633        }
19634
19635        // input_decorator_test.dart 'Material2 - counter text has correct right margin - RTL, not
19636        // dense'.
19637        #[test]
19638        fn material2_counter_right_margin_rtl_not_dense() {
19639            test_widgets(|tester| {
19640                // Margin for text decoration is 12 when filled and top left offset is (0, 0)
19641                // 0 + 12 = 12.
19642                let (size, _, counter) = counter_layout(tester, TextDirection::Rtl, false);
19643                assert_eq!(size, Size::new(800.0, 68.0));
19644                assert_eq!(counter.left, 12.0);
19645            });
19646        }
19647
19648        // input_decorator_test.dart 'Material2 - counter text has correct right margin - LTR,
19649        // dense'.
19650        #[test]
19651        fn material2_counter_right_margin_ltr_dense() {
19652            test_widgets(|tester| {
19653                let (size, decorator, counter) = counter_layout(tester, TextDirection::Ltr, true);
19654                assert_eq!(size, Size::new(800.0, 52.0));
19655                assert_eq!(counter.right, decorator.right - 12.0);
19656            });
19657        }
19658
19659        // input_decorator_test.dart 'Material2 - counter text has correct right margin - RTL, dense'.
19660        #[test]
19661        fn material2_counter_right_margin_rtl_dense() {
19662            test_widgets(|tester| {
19663                let (size, _, counter) = counter_layout(tester, TextDirection::Rtl, true);
19664                assert_eq!(size, Size::new(800.0, 52.0));
19665                assert_eq!(counter.left, 12.0);
19666            });
19667        }
19668
19669        // input_decorator_test.dart 'Material2 - InputDecorator error/helper/counter RTL layout'.
19670        #[test]
19671        fn material2_error_helper_and_counter_rtl_layout() {
19672            test_widgets(|tester| {
19673                M2::new(
19674                    InputDecoration::new()
19675                        .label_text(LABEL_TEXT)
19676                        .helper_text(HELPER_TEXT)
19677                        .counter_text(COUNTER_TEXT)
19678                        .filled(true),
19679                )
19680                .text_direction(TextDirection::Rtl)
19681                .pump(tester);
19682
19683                assert_eq!(decorator_size(tester), Size::new(800.0, 76.0));
19684                assert_eq!(top(tester, INPUT_TEXT), 28.0);
19685                assert_eq!(bottom(tester, INPUT_TEXT), 44.0);
19686                assert_eq!(top(tester, LABEL_TEXT), 12.0);
19687                assert_eq!(bottom(tester, LABEL_TEXT), 24.0);
19688                assert_eq!(get_border_bottom(tester), 56.0);
19689                assert_eq!(get_border_weight(tester), 1.0);
19690                assert_eq!(
19691                    tester.get_rect(find::text(COUNTER_TEXT)).top_left(),
19692                    Offset::new(12.0, 64.0)
19693                );
19694                assert_eq!(
19695                    tester.get_rect(find::text(HELPER_TEXT)).top_right(),
19696                    Offset::new(788.0, 64.0)
19697                );
19698
19699                // If both error and helper are specified, show the error
19700                M2::new(
19701                    InputDecoration::new()
19702                        .label_text(LABEL_TEXT)
19703                        .helper_text(HELPER_TEXT)
19704                        .error_text(ERROR_TEXT)
19705                        .counter_text(COUNTER_TEXT)
19706                        .filled(true),
19707                )
19708                .text_direction(TextDirection::Rtl)
19709                .pump(tester);
19710                tester.pump_and_settle();
19711                assert_eq!(
19712                    tester.get_rect(find::text(COUNTER_TEXT)).top_left(),
19713                    Offset::new(12.0, 64.0)
19714                );
19715                assert_eq!(
19716                    tester.get_rect(find::text(ERROR_TEXT)).top_right(),
19717                    Offset::new(788.0, 64.0)
19718                );
19719                expect(tester, &find::text(HELPER_TEXT), finds_nothing());
19720            });
19721        }
19722
19723        // input_decorator_test.dart 'Material2 - InputDecorator prefix/suffix RTL'.
19724        #[test]
19725        fn material2_prefix_and_suffix_rtl() {
19726            test_widgets(|tester| {
19727                M2::new(
19728                    InputDecoration::new()
19729                        .prefix_text("p")
19730                        .suffix_text("s")
19731                        .filled(true),
19732                )
19733                .text_direction(TextDirection::Rtl)
19734                .pump(tester);
19735
19736                assert_eq!(
19737                    decorator_size(tester),
19738                    Size::new(800.0, K_MIN_INTERACTIVE_DIMENSION)
19739                ); // 40 bumped up to minimum.
19740                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 16.0);
19741                assert_eq!(tester.get_rect(find::text("p")).height(), 16.0);
19742                assert_eq!(tester.get_rect(find::text("s")).height(), 16.0);
19743                assert_eq!(top(tester, INPUT_TEXT), 16.0);
19744                assert_eq!(top(tester, "p"), 16.0);
19745                assert_eq!(top(tester, "s"), 16.0);
19746
19747                // layout is a row: [s text p]
19748                assert_eq!(tester.get_rect(find::text("s")).left, 12.0);
19749                assert!(
19750                    tester.get_rect(find::text("s")).right
19751                        <= tester.get_rect(find::text(INPUT_TEXT)).left
19752                );
19753                assert!(
19754                    tester.get_rect(find::text(INPUT_TEXT)).right
19755                        <= tester.get_rect(find::text("p")).left
19756                );
19757            });
19758        }
19759
19760        // input_decorator_test.dart 'Material2 - InputDecorator contentPadding RTL layout'.
19761        #[test]
19762        fn material2_content_padding_rtl_layout() {
19763            test_widgets(|tester| {
19764                let decoration = || {
19765                    InputDecoration::new()
19766                        .content_padding(EdgeInsetsGeometry::from(EdgeInsetsDirectional::only(
19767                            40.0, 12.0, 0.0, 12.0,
19768                        )))
19769                        .label_text(LABEL_TEXT)
19770                        .hint_text(HINT_TEXT)
19771                        .filled(true)
19772                };
19773                // LTR: content left edge is contentPadding.start: 40.0
19774                M2::new(decoration()).pump(tester);
19775                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
19776                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).left, 40.0);
19777                assert_eq!(tester.get_rect(find::text(LABEL_TEXT)).left, 40.0);
19778                assert_eq!(tester.get_rect(find::text(HINT_TEXT)).left, 40.0);
19779
19780                // RTL: content right edge is 800 - contentPadding.start: 760.0.
19781                M2::new(decoration())
19782                    .is_focused(true) // label is floating, still adjusted for contentPadding
19783                    .text_direction(TextDirection::Rtl)
19784                    .pump(tester);
19785                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
19786                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).right, 760.0);
19787                assert_eq!(tester.get_rect(find::text(LABEL_TEXT)).right, 760.0);
19788                assert_eq!(tester.get_rect(find::text(HINT_TEXT)).right, 760.0);
19789            });
19790        }
19791
19792        fn check_input_width(
19793            tester: &mut WidgetTester,
19794            decoration: InputDecoration,
19795            height: f64,
19796            left: f64,
19797            right: f64,
19798        ) {
19799            M2::new(decoration).pump(tester);
19800            assert_eq!(decorator_size(tester), Size::new(800.0, height));
19801            assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).left, left);
19802            assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).right, right);
19803        }
19804
19805        // input_decorator_test.dart 'Material2 - inputText width - outline textField'.
19806        #[test]
19807        fn material2_outline_input_text_width() {
19808            test_widgets(|tester| {
19809                check_input_width(
19810                    tester,
19811                    InputDecoration::new().border(OutlineInputBorder::new()),
19812                    56.0,
19813                    12.0,
19814                    788.0,
19815                );
19816            });
19817        }
19818
19819        // input_decorator_test.dart 'Material2 - inputText width - outline textField with prefix and
19820        // suffix icons'.
19821        #[test]
19822        fn material2_outline_input_text_width_with_prefix_and_suffix_icons() {
19823            test_widgets(|tester| {
19824                check_input_width(
19825                    tester,
19826                    InputDecoration::new()
19827                        .border(OutlineInputBorder::new())
19828                        .prefix_icon(Icon::new(Some(Icons::visibility())))
19829                        .suffix_icon(Icon::new(Some(Icons::close()))),
19830                    56.0,
19831                    48.0,
19832                    752.0,
19833                );
19834            });
19835        }
19836
19837        // input_decorator_test.dart 'Material2 - inputText width - filled textField'.
19838        #[test]
19839        fn material2_filled_input_text_width() {
19840            test_widgets(|tester| {
19841                check_input_width(
19842                    tester,
19843                    InputDecoration::new().filled(true),
19844                    48.0,
19845                    12.0,
19846                    788.0,
19847                );
19848            });
19849        }
19850
19851        // input_decorator_test.dart 'Material2 - inputText width - filled textField with prefix and
19852        // suffix icons'.
19853        #[test]
19854        fn material2_filled_input_text_width_with_prefix_and_suffix_icons() {
19855            test_widgets(|tester| {
19856                check_input_width(
19857                    tester,
19858                    InputDecoration::new()
19859                        .filled(true)
19860                        .prefix_icon(Icon::new(Some(Icons::visibility())))
19861                        .suffix_icon(Icon::new(Some(Icons::close()))),
19862                    48.0,
19863                    48.0,
19864                    752.0,
19865                );
19866            });
19867        }
19868
19869        /// The label's rect in Dart's `buildInputDecoratorWithFloatingLabel` of the Material 2
19870        /// 'floatingLabelAlignment' group.
19871        fn floating_label_rect(
19872            tester: &mut WidgetTester,
19873            text_direction: TextDirection,
19874            has_icon: bool,
19875            alignment: FloatingLabelAlignment,
19876            border_is_outline: bool,
19877        ) -> Rect {
19878            let mut decoration = InputDecoration::new()
19879                .content_padding(EdgeInsetsGeometry::from(EdgeInsetsDirectional::only(
19880                    40.0, 12.0, 0.0, 12.0,
19881                )))
19882                .floating_label_alignment(alignment)
19883                .label_text(LABEL_TEXT)
19884                .hint_text(HINT_TEXT)
19885                .filled(true);
19886            if has_icon {
19887                decoration = decoration.icon(Icon::new(Some(Icons::insert_link())));
19888            }
19889            if border_is_outline {
19890                decoration = decoration.border(OutlineInputBorder::new());
19891            }
19892            M2::new(decoration)
19893                .text_direction(text_direction)
19894                .pump(tester);
19895            get_label_rect(tester)
19896        }
19897
19898        // input_decorator_test.dart 'Material2 - floatingLabelAlignment - LTR with icon aligned -
19899        // start'.
19900        #[test]
19901        fn material2_floating_label_starts_after_the_icon_ltr() {
19902            test_widgets(|tester| {
19903                for outline in [false, true] {
19904                    // icon (40) + contentPadding (40)
19905                    let rect = floating_label_rect(
19906                        tester,
19907                        TextDirection::Ltr,
19908                        true,
19909                        FloatingLabelAlignment::START,
19910                        outline,
19911                    );
19912                    assert_eq!(rect.left, 80.0);
19913                }
19914            });
19915        }
19916
19917        // input_decorator_test.dart 'Material2 - floatingLabelAlignment - LTR with icon aligned -
19918        // center'.
19919        #[test]
19920        fn material2_floating_label_centers_beside_the_icon_ltr() {
19921            test_widgets(|tester| {
19922                for outline in [false, true] {
19923                    // icon (40) + (decorator (800) - icon (40)) / 2
19924                    let rect = floating_label_rect(
19925                        tester,
19926                        TextDirection::Ltr,
19927                        true,
19928                        FloatingLabelAlignment::CENTER,
19929                        outline,
19930                    );
19931                    assert_eq!(rect.center().dx(), 420.0);
19932                }
19933            });
19934        }
19935
19936        // input_decorator_test.dart 'Material2 - floatingLabelAlignment - LTR without icon aligned -
19937        // start'.
19938        #[test]
19939        fn material2_floating_label_starts_at_the_padding_ltr() {
19940            test_widgets(|tester| {
19941                for outline in [false, true] {
19942                    // contentPadding (40)
19943                    let rect = floating_label_rect(
19944                        tester,
19945                        TextDirection::Ltr,
19946                        false,
19947                        FloatingLabelAlignment::START,
19948                        outline,
19949                    );
19950                    assert_eq!(rect.left, 40.0);
19951                }
19952            });
19953        }
19954
19955        // input_decorator_test.dart 'Material2 - floatingLabelAlignment - LTR without icon aligned -
19956        // center'.
19957        #[test]
19958        fn material2_floating_label_centers_in_the_decorator_ltr() {
19959            test_widgets(|tester| {
19960                for outline in [false, true] {
19961                    // decorator (800) / 2
19962                    let rect = floating_label_rect(
19963                        tester,
19964                        TextDirection::Ltr,
19965                        false,
19966                        FloatingLabelAlignment::CENTER,
19967                        outline,
19968                    );
19969                    assert_eq!(rect.center().dx(), 400.0);
19970                }
19971            });
19972        }
19973
19974        // input_decorator_test.dart 'Material2 - floatingLabelAlignment - RTL with icon aligned -
19975        // start'.
19976        #[test]
19977        fn material2_floating_label_starts_after_the_icon_rtl() {
19978            test_widgets(|tester| {
19979                for outline in [false, true] {
19980                    // decorator (800) - icon (40) - contentPadding (40)
19981                    let rect = floating_label_rect(
19982                        tester,
19983                        TextDirection::Rtl,
19984                        true,
19985                        FloatingLabelAlignment::START,
19986                        outline,
19987                    );
19988                    assert_eq!(rect.right, 720.0);
19989                }
19990            });
19991        }
19992
19993        // input_decorator_test.dart 'Material2 - floatingLabelAlignment - RTL with icon aligned -
19994        // center'.
19995        #[test]
19996        fn material2_floating_label_centers_beside_the_icon_rtl() {
19997            test_widgets(|tester| {
19998                for outline in [false, true] {
19999                    // (decorator (800) / icon (40)) / 2
20000                    let rect = floating_label_rect(
20001                        tester,
20002                        TextDirection::Rtl,
20003                        true,
20004                        FloatingLabelAlignment::CENTER,
20005                        outline,
20006                    );
20007                    assert_eq!(rect.center().dx(), 380.0);
20008                }
20009            });
20010        }
20011
20012        // input_decorator_test.dart 'Material2 - floatingLabelAlignment - RTL without icon aligned -
20013        // start'.
20014        #[test]
20015        fn material2_floating_label_starts_at_the_padding_rtl() {
20016            test_widgets(|tester| {
20017                for outline in [false, true] {
20018                    // decorator (800) - contentPadding (40)
20019                    let rect = floating_label_rect(
20020                        tester,
20021                        TextDirection::Rtl,
20022                        false,
20023                        FloatingLabelAlignment::START,
20024                        outline,
20025                    );
20026                    assert_eq!(rect.right, 760.0);
20027                }
20028            });
20029        }
20030
20031        // input_decorator_test.dart 'Material2 - floatingLabelAlignment - RTL without icon aligned -
20032        // center'.
20033        #[test]
20034        fn material2_floating_label_centers_in_the_decorator_rtl() {
20035            test_widgets(|tester| {
20036                for outline in [false, true] {
20037                    // decorator (800) / 2
20038                    let rect = floating_label_rect(
20039                        tester,
20040                        TextDirection::Rtl,
20041                        false,
20042                        FloatingLabelAlignment::CENTER,
20043                        outline,
20044                    );
20045                    assert_eq!(rect.center().dx(), 400.0);
20046                }
20047            });
20048        }
20049
20050        // input_decorator_test.dart 'Material2 - InputDecorator prefix/suffix dense layout'.
20051        #[test]
20052        fn material2_prefix_and_suffix_dense_layout() {
20053            test_widgets(|tester| {
20054                M2::new(
20055                    InputDecoration::new()
20056                        .is_dense(true)
20057                        .prefix_text("p")
20058                        .suffix_text("s")
20059                        .filled(true),
20060                )
20061                .is_focused(true)
20062                .pump(tester);
20063
20064                // The only difference from normal layout for this case is that the
20065                // padding above and below the prefix, input text, suffix, is 8 instead of 12.
20066                assert_eq!(decorator_size(tester), Size::new(800.0, 32.0));
20067                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 16.0);
20068                assert_eq!(tester.get_rect(find::text("p")).height(), 16.0);
20069                assert_eq!(tester.get_rect(find::text("s")).height(), 16.0);
20070                assert_eq!(top(tester, INPUT_TEXT), 8.0);
20071                assert_eq!(top(tester, "p"), 8.0);
20072                assert_eq!(tester.get_rect(find::text("p")).left, 12.0);
20073                assert_eq!(top(tester, "s"), 8.0);
20074                assert_eq!(tester.get_rect(find::text("s")).right, 788.0);
20075
20076                // layout is a row: [p text s]
20077                assert_eq!(tester.get_rect(find::text("p")).left, 12.0);
20078                assert!(
20079                    tester.get_rect(find::text("p")).right
20080                        <= tester.get_rect(find::text(INPUT_TEXT)).left
20081                );
20082                assert!(
20083                    tester.get_rect(find::text(INPUT_TEXT)).right
20084                        <= tester.get_rect(find::text("s")).left
20085                );
20086
20087                assert_eq!(get_border_bottom(tester), 32.0);
20088                assert_eq!(get_border_weight(tester), 2.0);
20089            });
20090        }
20091
20092        // input_decorator_test.dart 'Material2 - InputDecorator with empty InputDecoration'.
20093        #[test]
20094        fn material2_empty_decoration_is_bumped_up_to_the_minimum_height() {
20095            test_widgets(|tester| {
20096                M2::new(InputDecoration::new()).pump(tester);
20097
20098                assert_eq!(
20099                    decorator_size(tester),
20100                    Size::new(800.0, K_MIN_INTERACTIVE_DIMENSION)
20101                ); // 40 bumped up to minimum.
20102                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 16.0);
20103                assert_eq!(top(tester, INPUT_TEXT), 16.0);
20104                assert_eq!(get_border_bottom(tester), K_MIN_INTERACTIVE_DIMENSION); // 40 bumped up to minimum.
20105                assert_eq!(get_border_weight(tester), 1.0);
20106            });
20107        }
20108
20109        // input_decorator_test.dart 'Material2 - contentPadding smaller than
20110        // kMinInteractiveDimension'.
20111        #[test]
20112        fn material2_content_padding_smaller_than_the_minimum_interactive_dimension() {
20113            test_widgets(|tester| {
20114                const VERTICAL_PADDING: f64 = 1.0;
20115                M2::new(
20116                    InputDecoration::new()
20117                        .hint_text(HINT_TEXT)
20118                        .content_padding(EdgeInsetsGeometry::from(EdgeInsets::symmetric(
20119                            VERTICAL_PADDING,
20120                            0.0,
20121                        )))
20122                        .is_dense(true),
20123                )
20124                .pump(tester);
20125
20126                // The overall height is 18dps. This is shorter than
20127                // kMinInteractiveDimension, but because isDense is true, the minimum is
20128                // ignored.
20129                assert_eq!(decorator_size(tester), Size::new(800.0, 18.0));
20130                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 16.0);
20131                assert_eq!(top(tester, INPUT_TEXT), 1.0);
20132                assert_eq!(get_opacity(tester, HINT_TEXT), 0.0);
20133                assert_eq!(get_border_weight(tester), 1.0);
20134
20135                // InputDecoration.collapsed does not support contentPadding
20136                M2::new(InputDecoration::collapsed(None).hint_text(HINT_TEXT)).pump(tester);
20137
20138                // The overall height is 16dps. This is shorter than
20139                // kMinInteractiveDimension, but because isCollapsed is true, the minimum is
20140                // ignored. There is no padding at all, because isCollapsed doesn't support
20141                // contentPadding.
20142                assert_eq!(decorator_size(tester), Size::new(800.0, 16.0));
20143                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 16.0);
20144                assert_eq!(top(tester, INPUT_TEXT), 0.0);
20145                assert_eq!(get_opacity(tester, HINT_TEXT), 0.0);
20146                assert_eq!(get_border_weight(tester), 1.0);
20147
20148                M2::new(InputDecoration::new().hint_text(HINT_TEXT).content_padding(
20149                    EdgeInsetsGeometry::from(EdgeInsets::symmetric(VERTICAL_PADDING, 0.0)),
20150                ))
20151                .pump(tester);
20152
20153                // The requested overall height is 18dps, however the minimum height is
20154                // kMinInteractiveDimension because neither isDense or isCollapsed are true.
20155                assert_eq!(
20156                    decorator_size(tester),
20157                    Size::new(800.0, K_MIN_INTERACTIVE_DIMENSION)
20158                );
20159                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 16.0);
20160                assert_eq!(top(tester, INPUT_TEXT), 16.0);
20161                assert_eq!(get_opacity(tester, HINT_TEXT), 0.0);
20162                assert_eq!(get_border_weight(tester), 0.0);
20163            });
20164        }
20165
20166        // input_decorator_test.dart 'Material2 - InputDecorator.collapsed'.
20167        #[test]
20168        fn material2_collapsed_decorator_has_no_minimum_height() {
20169            test_widgets(|tester| {
20170                M2::new(InputDecoration::collapsed(None).hint_text(HINT_TEXT)).pump(tester);
20171
20172                // Overall height for this InputDecorator is 16dps. There is no minimum
20173                // height when InputDecoration.collapsed is used.
20174                assert_eq!(decorator_size(tester), Size::new(800.0, 16.0));
20175                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 16.0);
20176                assert_eq!(top(tester, INPUT_TEXT), 0.0);
20177                assert_eq!(get_opacity(tester, HINT_TEXT), 0.0);
20178                assert_eq!(get_border_weight(tester), 0.0);
20179
20180                // The hint should appear
20181                M2::new(InputDecoration::collapsed(None).hint_text(HINT_TEXT))
20182                    .is_empty(true)
20183                    .is_focused(true)
20184                    .pump(tester);
20185                tester.pump_and_settle();
20186
20187                assert_eq!(decorator_size(tester), Size::new(800.0, 16.0));
20188                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 16.0);
20189                assert_eq!(top(tester, INPUT_TEXT), 0.0);
20190                assert_eq!(tester.get_rect(find::text(HINT_TEXT)).height(), 16.0);
20191                assert_eq!(top(tester, HINT_TEXT), 0.0);
20192                assert_eq!(get_border_weight(tester), 0.0);
20193            });
20194        }
20195
20196        // input_decorator_test.dart 'Material2 - InputDecorator with baseStyle'.
20197        #[test]
20198        fn material2_decorator_with_base_style() {
20199            test_widgets(|tester| {
20200                // Setting the baseStyle of the InputDecoration and the style of the input
20201                // text child to a smaller font reduces the InputDecoration's vertical size.
20202                let style = TextStyle::new().font_size(10.0);
20203                M2::new(
20204                    InputDecoration::new()
20205                        .hint_text(HINT_TEXT)
20206                        .label_text(LABEL_TEXT),
20207                )
20208                .is_empty(true)
20209                .base_style(style.clone())
20210                .child(Text::new(INPUT_TEXT).style(style))
20211                .pump(tester);
20212
20213                assert_eq!(
20214                    decorator_size(tester),
20215                    Size::new(800.0, K_MIN_INTERACTIVE_DIMENSION)
20216                ); // 45.5 bumped up to minimum.
20217                assert_eq!(tester.get_rect(find::text(HINT_TEXT)).height(), 10.0);
20218                assert_eq!(tester.get_rect(find::text(LABEL_TEXT)).height(), 10.0);
20219                assert_eq!(tester.get_rect(find::text(INPUT_TEXT)).height(), 10.0);
20220                assert_eq!(top(tester, HINT_TEXT), 24.75);
20221                assert_eq!(top(tester, LABEL_TEXT), 19.0);
20222                assert_eq!(top(tester, INPUT_TEXT), 24.75);
20223            });
20224        }
20225
20226        // input_decorator_test.dart 'Material2 - InputDecorator with empty style overrides'.
20227        #[test]
20228        fn material2_empty_style_overrides_lay_out_as_no_overrides() {
20229            test_widgets(|tester| {
20230                // Same as not specifying any style overrides
20231                M2::new(
20232                    InputDecoration::new()
20233                        .label_text(LABEL_TEXT)
20234                        .hint_text(HINT_TEXT)
20235                        .helper_text(HELPER_TEXT)
20236                        .counter_text(COUNTER_TEXT)
20237                        .label_style(TextStyle::new())
20238                        .hint_style(TextStyle::new())
20239                        .error_style(TextStyle::new())
20240                        .helper_style(TextStyle::new())
20241                        .filled(true),
20242                )
20243                .pump(tester);
20244
20245                // Label is floating because isEmpty is false.
20246                assert_eq!(decorator_size(tester), Size::new(800.0, 76.0));
20247                assert_eq!(top(tester, INPUT_TEXT), 28.0);
20248                assert_eq!(bottom(tester, INPUT_TEXT), 44.0);
20249                assert_eq!(top(tester, LABEL_TEXT), 12.0);
20250                assert_eq!(bottom(tester, LABEL_TEXT), 24.0);
20251                assert_eq!(get_border_bottom(tester), 56.0);
20252                assert_eq!(get_border_weight(tester), 1.0);
20253                assert_eq!(
20254                    tester.get_rect(find::text(HELPER_TEXT)).top_left(),
20255                    Offset::new(12.0, 64.0)
20256                );
20257                assert_eq!(
20258                    tester.get_rect(find::text(COUNTER_TEXT)).top_right(),
20259                    Offset::new(788.0, 64.0)
20260                );
20261            });
20262        }
20263
20264        fn borderless_outline_never_floating() -> InputDecoration {
20265            InputDecoration::new()
20266                .border(OutlineInputBorder::new().border_side(BorderSide::NONE))
20267                .floating_label_behavior(FloatingLabelBehavior::Never)
20268                .label_text(LABEL_TEXT)
20269        }
20270
20271        // input_decorator_test.dart 'Material2 - InputDecoration outline shape with no border and no
20272        // floating placeholder'.
20273        #[test]
20274        fn material2_outline_shape_with_no_border_and_no_floating_placeholder() {
20275            test_widgets(|tester| {
20276                M2::new(borderless_outline_never_floating())
20277                    .is_empty(true)
20278                    .pump(tester);
20279
20280                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
20281                assert_eq!(top(tester, LABEL_TEXT), 20.0);
20282                assert_eq!(bottom(tester, LABEL_TEXT), 36.0);
20283                assert_eq!(get_border_bottom(tester), 56.0);
20284                assert_eq!(get_border_weight(tester), 0.0);
20285            });
20286        }
20287
20288        // input_decorator_test.dart 'Material2 - InputDecoration outline shape with no border and no
20289        // floating placeholder not empty'.
20290        #[test]
20291        fn material2_outline_shape_with_no_border_and_no_floating_placeholder_not_empty() {
20292            test_widgets(|tester| {
20293                M2::new(borderless_outline_never_floating()).pump(tester);
20294
20295                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
20296                assert_eq!(top(tester, LABEL_TEXT), 20.0);
20297                assert_eq!(bottom(tester, LABEL_TEXT), 36.0);
20298                assert_eq!(get_border_bottom(tester), 56.0);
20299                assert_eq!(get_border_weight(tester), 0.0);
20300
20301                // The label should not be seen.
20302                assert_eq!(get_opacity(tester, LABEL_TEXT), 0.0);
20303            });
20304        }
20305
20306        // input_decorator_test.dart 'Material2 - InputDecorationThemeData outline border'.
20307        #[test]
20308        fn material2_theme_outline_border_centers_the_label() {
20309            test_widgets(|tester| {
20310                M2::new(InputDecoration::new().label_text(LABEL_TEXT))
20311                    .is_empty(true) // label appears, vertically centered
20312                    .input_decoration_theme(
20313                        InputDecorationThemeData::new().border(OutlineInputBorder::new()),
20314                    )
20315                    .pump(tester);
20316
20317                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
20318                assert_eq!(top(tester, LABEL_TEXT), 20.0);
20319                assert_eq!(bottom(tester, LABEL_TEXT), 36.0);
20320                assert_eq!(get_border_bottom(tester), 56.0);
20321                assert_eq!(get_border_weight(tester), 1.0);
20322            });
20323        }
20324
20325        // input_decorator_test.dart 'Material2 - InputDecorationThemeData outline border, dense
20326        // layout'.
20327        #[test]
20328        fn material2_theme_outline_border_dense_layout() {
20329            test_widgets(|tester| {
20330                M2::new(label_and_hint())
20331                    .is_empty(true) // label appears, vertically centered
20332                    .input_decoration_theme(
20333                        InputDecorationThemeData::new()
20334                            .border(OutlineInputBorder::new())
20335                            .is_dense(true),
20336                    )
20337                    .pump(tester);
20338
20339                assert_eq!(decorator_size(tester), Size::new(800.0, 48.0));
20340                assert_eq!(top(tester, LABEL_TEXT), 16.0);
20341                assert_eq!(bottom(tester, LABEL_TEXT), 32.0);
20342                assert_eq!(get_border_bottom(tester), 48.0);
20343                assert_eq!(get_border_weight(tester), 1.0);
20344            });
20345        }
20346
20347        /// The styles of 'InputDecorationThemeData style overrides' and its focused twin.
20348        struct OverrideStyles {
20349            label_style: TextStyle,
20350            floating_label_style: TextStyle,
20351            hint_style: TextStyle,
20352            prefix_style: TextStyle,
20353            suffix_style: TextStyle,
20354            helper_style: TextStyle,
20355            counter_style: TextStyle,
20356        }
20357
20358        impl OverrideStyles {
20359            fn new() -> OverrideStyles {
20360                let default_style = TextStyle::new().font_size(16.0);
20361                let style12 = TextStyle::new().font_size(12.0);
20362                let with_color = |style: &TextStyle, color: Color| {
20363                    style.merge(Some(&TextStyle::new().color(color)))
20364                };
20365                OverrideStyles {
20366                    label_style: with_color(&default_style, Colors::RED.primary()),
20367                    floating_label_style: with_color(&default_style, Colors::INDIGO.primary()),
20368                    hint_style: with_color(&default_style, Colors::GREEN.primary()),
20369                    prefix_style: with_color(&default_style, Colors::BLUE.primary()),
20370                    suffix_style: with_color(&default_style, Colors::PURPLE.primary()),
20371                    helper_style: with_color(&style12, Colors::ORANGE.primary()),
20372                    counter_style: with_color(&style12, Colors::ORANGE.primary()),
20373                }
20374            }
20375
20376            fn theme(&self, floating: bool) -> InputDecorationThemeData {
20377                let mut theme = InputDecorationThemeData::new()
20378                    .label_style(self.label_style.clone())
20379                    .hint_style(self.hint_style.clone())
20380                    .prefix_style(self.prefix_style.clone())
20381                    .suffix_style(self.suffix_style.clone())
20382                    .helper_style(self.helper_style.clone())
20383                    .counter_style(self.counter_style.clone());
20384                if floating {
20385                    theme = theme.floating_label_style(self.floating_label_style.clone());
20386                }
20387                // filled: false (default) - don't pad by left/right 12dps
20388                theme
20389            }
20390        }
20391
20392        fn text_style_color(tester: &WidgetTester, text: &str) -> Option<Color> {
20393            let element = tester.element(find::text(text));
20394            tester.widget(element, |text: &waft_widgets::Text| {
20395                text.style
20396                    .as_ref()
20397                    .and_then(|style| style.color.as_ref().map(|color| **color))
20398            })
20399        }
20400
20401        fn color_of(style: &TextStyle) -> Option<Color> {
20402            style.color.as_ref().map(|color| **color)
20403        }
20404
20405        /// Dart's 'InputDecorationThemeData style overrides' (and its focused twin): the layout
20406        /// with the overridden styles' metrics, then the styles passed along with
20407        /// Dart's strings.
20408        fn check_style_overrides(
20409            tester: &mut WidgetTester,
20410            focused: bool,
20411            label_top: f64,
20412            label_height: f64,
20413            weight: f64,
20414        ) {
20415            let styles = OverrideStyles::new();
20416            M2::new(
20417                InputDecoration::new()
20418                    .label_text(LABEL_TEXT)
20419                    .hint_text(HINT_TEXT)
20420                    .prefix_text("prefix")
20421                    .suffix_text("suffix")
20422                    .helper_text(HELPER_TEXT)
20423                    .counter_text(COUNTER_TEXT),
20424            )
20425            .is_empty(true)
20426            .is_focused(focused)
20427            .input_decoration_theme(styles.theme(focused))
20428            .pump(tester);
20429
20430            // Overall height for this InputDecorator is 76dps.
20431            assert_eq!(decorator_size(tester), Size::new(800.0, 76.0));
20432            assert_eq!(top(tester, LABEL_TEXT), label_top);
20433            assert_eq!(bottom(tester, LABEL_TEXT), label_top + label_height);
20434            assert_eq!(get_border_bottom(tester), 56.0);
20435            assert_eq!(get_border_weight(tester), weight);
20436            assert_eq!(
20437                tester.get_rect(find::text(HELPER_TEXT)).top_left(),
20438                Offset::new(0.0, 64.0)
20439            );
20440            assert_eq!(
20441                tester.get_rect(find::text(COUNTER_TEXT)).top_right(),
20442                Offset::new(800.0, 64.0)
20443            );
20444
20445            // Verify that the styles were passed along
20446            M2::new(
20447                InputDecoration::new()
20448                    .label_text(LABEL_TEXT)
20449                    .hint_text(HINT_TEXT)
20450                    .prefix_text("prefix")
20451                    .suffix_text("suffix")
20452                    .helper_text(HELPER_TEXT)
20453                    .counter_text(COUNTER_TEXT),
20454            )
20455            .is_empty(true)
20456            .is_focused(focused)
20457            .input_decoration_theme(styles.theme(focused))
20458            .pump(tester);
20459            assert_eq!(
20460                text_style_color(tester, HINT_TEXT),
20461                color_of(&styles.hint_style)
20462            );
20463            assert_eq!(
20464                text_style_color(tester, "prefix"),
20465                color_of(&styles.prefix_style)
20466            );
20467            assert_eq!(
20468                text_style_color(tester, "suffix"),
20469                color_of(&styles.suffix_style)
20470            );
20471            assert_eq!(
20472                text_style_color(tester, HELPER_TEXT),
20473                color_of(&styles.helper_style)
20474            );
20475            assert_eq!(
20476                text_style_color(tester, COUNTER_TEXT),
20477                color_of(&styles.counter_style)
20478            );
20479            let label_style = if focused {
20480                &styles.floating_label_style
20481            } else {
20482                &styles.label_style
20483            };
20484            assert_eq!(color_of(&get_label_style(tester)), color_of(label_style));
20485        }
20486
20487        // input_decorator_test.dart 'Material2 - InputDecorationThemeData style overrides'.
20488        #[test]
20489        fn material2_theme_style_overrides() {
20490            test_widgets(|tester| check_style_overrides(tester, false, 20.0, 16.0, 1.0));
20491        }
20492
20493        // input_decorator_test.dart 'Material2 - InputDecorationThemeData style overrides
20494        // (focused)'.
20495        #[test]
20496        fn material2_theme_style_overrides_focused() {
20497            test_widgets(|tester| check_style_overrides(tester, true, 12.0, 12.0, 2.0));
20498        }
20499
20500        // input_decorator_test.dart 'Material2 - InputDecorator with empty border and label'.
20501        #[test]
20502        fn material2_empty_border_with_a_label() {
20503            test_widgets(|tester| {
20504                // Regression test for https://github.com/flutter/flutter/issues/14165
20505                M2::new(
20506                    InputDecoration::new()
20507                        .label_text(LABEL_TEXT)
20508                        .border(InputBorderRef::none()),
20509                )
20510                .pump(tester);
20511
20512                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
20513                assert_eq!(get_border_weight(tester), 0.0);
20514                assert_eq!(top(tester, LABEL_TEXT), 12.0);
20515                assert_eq!(bottom(tester, LABEL_TEXT), 24.0);
20516            });
20517        }
20518
20519        fn outline_with(color: Color) -> InputBorderRef {
20520            InputBorderRef::new(OutlineInputBorder::new().border_side(BorderSide {
20521                color,
20522                ..BorderSide::default()
20523            }))
20524        }
20525
20526        fn same_color(actual: Color, expected: Color) {
20527            assert!(
20528                crate::test_support::is_same_color_as(actual, expected),
20529                "{actual:?} is not the same colour as {expected:?}"
20530            );
20531        }
20532
20533        // input_decorator_test.dart 'Material2 - InputDecorator draws and animates hoverColor'.
20534        #[test]
20535        fn material2_decorator_draws_and_animates_hover_color() {
20536            test_widgets(|tester| {
20537                let fill_color = Color::new(0x0A000000);
20538                let hover_color = Color::new(0xFF00FF00);
20539                let disabled_color = Color::new(0x05000000);
20540                let enabled_border_color = Color::new(0x61000000);
20541
20542                let pump_decorator =
20543                    |tester: &mut WidgetTester, hovering: bool, enabled: bool, filled: bool| {
20544                        M2::new(
20545                            InputDecoration::new()
20546                                .enabled(enabled)
20547                                .filled(filled)
20548                                .hover_color(hover_color)
20549                                .disabled_border(outline_with(disabled_color))
20550                                .border(outline_with(enabled_border_color)),
20551                        )
20552                        .is_hovering(hovering)
20553                        .pump(tester);
20554                    };
20555
20556                // Test filled text field.
20557                pump_decorator(tester, false, true, true);
20558                same_color(get_container_color(tester), fill_color);
20559                tester.pump_by(Duration::from_secs(10));
20560                same_color(get_container_color(tester), fill_color);
20561
20562                pump_decorator(tester, true, true, true);
20563                same_color(get_container_color(tester), fill_color);
20564                tester.pump_by(Duration::from_millis(15));
20565                same_color(get_container_color(tester), hover_color);
20566
20567                pump_decorator(tester, false, true, true);
20568                same_color(get_container_color(tester), hover_color);
20569                tester.pump_by(Duration::from_millis(15));
20570                same_color(get_container_color(tester), fill_color);
20571
20572                // Test that for high refresh rate displays, the color mid-animation is somewhere
20573                // between the fill color and the hover color.
20574                pump_decorator(tester, true, true, true);
20575                same_color(get_container_color(tester), fill_color);
20576                tester.pump_by(Duration::from_millis(6));
20577                let hover_value =
20578                    with_border_painter(tester, |app, painter| painter.hover_animation.value(app));
20579                let mid_hover_color = Color::lerp(
20580                    Some(hover_color.with_alpha(0)),
20581                    Some(hover_color),
20582                    hover_value,
20583                )
20584                .expect("both colours are given");
20585                same_color(
20586                    get_container_color(tester),
20587                    Color::alpha_blend(mid_hover_color, fill_color),
20588                );
20589
20590                pump_decorator(tester, false, false, true);
20591                same_color(get_container_color(tester), disabled_color);
20592                tester.pump_by(Duration::from_secs(10));
20593                same_color(get_container_color(tester), disabled_color);
20594
20595                pump_decorator(tester, true, false, true);
20596                same_color(get_container_color(tester), disabled_color);
20597                tester.pump_by(Duration::from_secs(10));
20598                same_color(get_container_color(tester), disabled_color);
20599
20600                // Test outline text field.
20601                let blended_hover_color = Color::new(0x74004400);
20602                pump_decorator(tester, false, true, false);
20603                tester.pump_and_settle();
20604                same_color(get_border_color(tester), enabled_border_color);
20605                tester.pump_by(Duration::from_secs(10));
20606                same_color(get_border_color(tester), enabled_border_color);
20607
20608                pump_decorator(tester, true, true, false);
20609                same_color(get_border_color(tester), enabled_border_color);
20610                tester.pump_by(Duration::from_millis(167));
20611                same_color(get_border_color(tester), blended_hover_color);
20612
20613                pump_decorator(tester, false, true, false);
20614                same_color(get_border_color(tester), blended_hover_color);
20615                tester.pump_by(Duration::from_millis(167));
20616                same_color(get_border_color(tester), enabled_border_color);
20617
20618                pump_decorator(tester, false, false, false);
20619                same_color(get_border_color(tester), enabled_border_color);
20620                tester.pump_by(Duration::from_millis(167));
20621                same_color(get_border_color(tester), disabled_color);
20622
20623                pump_decorator(tester, true, false, false);
20624                same_color(get_border_color(tester), disabled_color);
20625                tester.pump_by(Duration::from_secs(10));
20626                same_color(get_border_color(tester), disabled_color);
20627            });
20628        }
20629
20630        // input_decorator_test.dart 'Material2 - InputDecorator draws and animates focusColor'.
20631        #[test]
20632        fn material2_decorator_draws_and_animates_focus_color() {
20633            test_widgets(|tester| {
20634                let focus_color = Color::new(0xFF0000FF);
20635                let disabled_color = Color::new(0x05000000);
20636                let enabled_border_color = Color::new(0x61000000);
20637
20638                let pump_decorator = |tester: &mut WidgetTester, focused: bool, enabled: bool| {
20639                    M2::new(
20640                        InputDecoration::new()
20641                            .enabled(enabled)
20642                            .filled(false)
20643                            .focus_color(focus_color)
20644                            .focused_border(outline_with(focus_color))
20645                            .disabled_border(outline_with(disabled_color))
20646                            .border(outline_with(enabled_border_color)),
20647                    )
20648                    .is_focused(focused)
20649                    .pump(tester);
20650                };
20651
20652                // Test outline text field default border.
20653                pump_decorator(tester, false, true);
20654                tester.pump_and_settle();
20655                assert_eq!(get_border_color(tester), enabled_border_color);
20656                tester.pump_by(Duration::from_secs(10));
20657                assert_eq!(get_border_color(tester), enabled_border_color);
20658
20659                pump_decorator(tester, true, true);
20660                assert_eq!(get_border_color(tester), enabled_border_color);
20661                tester.pump_by(Duration::from_millis(167));
20662                assert_eq!(get_border_color(tester), focus_color);
20663
20664                pump_decorator(tester, false, true);
20665                assert_eq!(get_border_color(tester), focus_color);
20666                tester.pump_by(Duration::from_millis(167));
20667                assert_eq!(get_border_color(tester), enabled_border_color);
20668
20669                pump_decorator(tester, false, false);
20670                assert_eq!(get_border_color(tester), enabled_border_color);
20671                tester.pump_by(Duration::from_millis(167));
20672                assert_eq!(get_border_color(tester), disabled_color);
20673
20674                pump_decorator(tester, true, false);
20675                assert_eq!(get_border_color(tester), disabled_color);
20676                tester.pump_by(Duration::from_secs(10));
20677                assert_eq!(get_border_color(tester), disabled_color);
20678            });
20679        }
20680
20681        // input_decorator_test.dart 'Material2 - InputDecorator withdraws label when not empty or
20682        // focused'.
20683        #[test]
20684        fn material2_decorator_withdraws_the_label_when_not_empty_or_focused() {
20685            test_widgets(|tester| {
20686                let pump_decorator =
20687                    |tester: &mut WidgetTester, focused: bool, enabled: bool, empty: bool| {
20688                        M2::new(
20689                            InputDecoration::new()
20690                                .label_text("Label")
20691                                .enabled(enabled)
20692                                .filled(false)
20693                                .focused_border(OutlineInputBorder::new())
20694                                .disabled_border(OutlineInputBorder::new())
20695                                .border(OutlineInputBorder::new()),
20696                        )
20697                        .is_empty(empty)
20698                        .is_focused(focused)
20699                        .pump(tester);
20700                        tester.pump_and_settle();
20701                    };
20702                let label_size = Size::new(80.0, 16.0);
20703                let floating_size = Size::new(80.0 * 0.75, 16.0 * 0.75);
20704                let check = |tester: &WidgetTester, top_left: Offset, size: Size| {
20705                    let rect = get_label_rect(tester);
20706                    assert_eq!(rect.top_left(), top_left);
20707                    assert_eq!(rect.size(), size);
20708                };
20709
20710                pump_decorator(tester, false, true, true);
20711                check(tester, Offset::new(12.0, 20.0), label_size);
20712
20713                pump_decorator(tester, false, true, false);
20714                check(tester, Offset::new(12.0, -5.5), floating_size);
20715
20716                pump_decorator(tester, true, true, true);
20717                check(tester, Offset::new(12.0, -5.5), floating_size);
20718
20719                pump_decorator(tester, true, true, false);
20720                check(tester, Offset::new(12.0, -5.5), floating_size);
20721
20722                pump_decorator(tester, false, false, true);
20723                check(tester, Offset::new(12.0, 20.0), label_size);
20724
20725                pump_decorator(tester, false, false, false);
20726                check(tester, Offset::new(12.0, -5.5), floating_size);
20727
20728                // Focused and disabled happens with NavigationMode.directional.
20729                pump_decorator(tester, true, false, true);
20730                check(tester, Offset::new(12.0, 20.0), label_size);
20731
20732                pump_decorator(tester, true, false, false);
20733                check(tester, Offset::new(12.0, -5.5), floating_size);
20734            });
20735        }
20736
20737        // input_decorator_test.dart 'Material2 - InputDecoration default border uses colorScheme'.
20738        #[test]
20739        #[allow(deprecated)]
20740        fn material2_default_border_uses_the_color_scheme() {
20741            test_widgets(|tester| {
20742                let theme = m2(&tester.cell.borrow());
20743                // Dart's `withOpacity`, deprecated there too.
20744                let enabled_color = theme.color_scheme.on_surface().with_opacity(0.38);
20745                let disabled_color = theme.disabled_color;
20746                let hover_color =
20747                    Color::alpha_blend(theme.hover_color.with_opacity(0.12), enabled_color);
20748
20749                // Enabled
20750                M2::new(InputDecoration::new()).theme(m2).pump(tester);
20751                tester.pump_and_settle();
20752                assert_eq!(get_border_color(tester), enabled_color);
20753
20754                // Filled
20755                M2::new(InputDecoration::new().filled(true))
20756                    .theme(m2)
20757                    .pump(tester);
20758                tester.pump_and_settle();
20759                assert_eq!(get_border_color(tester), theme.hint_color);
20760
20761                // Hovering
20762                M2::new(InputDecoration::new())
20763                    .theme(m2)
20764                    .is_hovering(true)
20765                    .pump(tester);
20766                tester.pump_and_settle();
20767                assert_eq!(get_border_color(tester), hover_color);
20768
20769                // Focused
20770                M2::new(InputDecoration::new())
20771                    .theme(m2)
20772                    .is_focused(true)
20773                    .pump(tester);
20774                tester.pump_and_settle();
20775                assert_eq!(get_border_color(tester), theme.color_scheme.primary());
20776
20777                // Error
20778                M2::new(InputDecoration::new().error_text("Nope"))
20779                    .theme(m2)
20780                    .pump(tester);
20781                tester.pump_and_settle();
20782                assert_eq!(get_border_color(tester), theme.color_scheme.error());
20783
20784                // Disabled
20785                M2::new(InputDecoration::new().enabled(false))
20786                    .theme(m2)
20787                    .pump(tester);
20788                tester.pump_and_settle();
20789                assert_eq!(get_border_color(tester), disabled_color);
20790
20791                // Disabled, filled
20792                M2::new(InputDecoration::new().enabled(false).filled(true))
20793                    .theme(m2)
20794                    .pump(tester);
20795                tester.pump_and_settle();
20796                assert_eq!(get_border_color(tester), Colors::TRANSPARENT);
20797            });
20798        }
20799
20800        fn outline(color: Color, width: f64) -> InputBorderRef {
20801            InputBorderRef::new(OutlineInputBorder::new().border_side(BorderSide {
20802                color,
20803                width,
20804                ..BorderSide::default()
20805            }))
20806        }
20807
20808        // input_decorator_test.dart 'Material2 - InputDecoration borders'.
20809        #[test]
20810        fn material2_decoration_borders_per_state() {
20811            test_widgets(|tester| {
20812                let error_border = outline(Colors::RED.primary(), 1.5);
20813                let focused_border = outline(Colors::GREEN.primary(), 4.0);
20814                let focused_error_border = outline(Colors::TEAL.primary(), 5.0);
20815                let disabled_border = outline(Colors::GREY.primary(), 0.0);
20816                let enabled_border = outline(Colors::BLUE.primary(), 2.5);
20817                let decoration = || {
20818                    InputDecoration::new()
20819                        .error_border(error_border.clone())
20820                        .focused_border(focused_border.clone())
20821                        .focused_error_border(focused_error_border.clone())
20822                        .disabled_border(disabled_border.clone())
20823                        .enabled_border(enabled_border.clone())
20824                };
20825                let check = |tester: &mut WidgetTester,
20826                             decoration: InputDecoration,
20827                             focused: bool,
20828                             expected: &dyn InputBorder| {
20829                    M2::new(decoration).is_focused(focused).pump(tester);
20830                    tester.pump_and_settle(); // border changes are animated
20831                    assert!(
20832                        *get_border(tester).unwrap() == *expected,
20833                        "{:?}",
20834                        get_border(tester).unwrap().border_side()
20835                    );
20836                };
20837
20838                check(tester, decoration(), false, &*enabled_border);
20839                check(tester, decoration(), true, &*focused_border);
20840                check(
20841                    tester,
20842                    decoration().error_text(ERROR_TEXT),
20843                    true,
20844                    &*focused_error_border,
20845                );
20846                check(
20847                    tester,
20848                    decoration().error_text(ERROR_TEXT),
20849                    false,
20850                    &*error_border,
20851                );
20852                check(
20853                    tester,
20854                    decoration().error_text(ERROR_TEXT).enabled(false),
20855                    false,
20856                    &*error_border,
20857                );
20858                check(
20859                    tester,
20860                    decoration().enabled(false),
20861                    false,
20862                    &*disabled_border,
20863                );
20864                check(tester, decoration().enabled(false), true, &*disabled_border);
20865            });
20866        }
20867
20868        // input_decorator_test.dart 'Material2 - InputDecorator floating label Y coordinate'.
20869        #[test]
20870        fn material2_floating_label_y_coordinate() {
20871            test_widgets(|tester| {
20872                // Regression test for https://github.com/flutter/flutter/issues/54028
20873                M2::new(
20874                    InputDecoration::new()
20875                        .label_text(LABEL_TEXT)
20876                        .enabled_border(OutlineInputBorder::new().border_side(BorderSide {
20877                            width: 4.0,
20878                            ..BorderSide::default()
20879                        }))
20880                        .floating_label_behavior(FloatingLabelBehavior::Always),
20881                )
20882                .is_empty(true)
20883                .pump(tester);
20884                tester.pump_and_settle();
20885
20886                // floatingLabelHeight = 12 (font size 16dps * 0.75 = 12)
20887                // labelY = -floatingLabelHeight/2 + borderWidth/2
20888                assert_eq!(top(tester, LABEL_TEXT), -4.0);
20889            });
20890        }
20891
20892        // input_decorator_test.dart 'Material2 - InputDecorator floating label obeys
20893        // floatingLabelBehavior'.
20894        #[test]
20895        fn material2_floating_label_obeys_floating_label_behavior() {
20896            test_widgets(|tester| {
20897                M2::new(
20898                    InputDecoration::new()
20899                        .label_text(LABEL_TEXT)
20900                        .floating_label_behavior(FloatingLabelBehavior::Never),
20901                )
20902                .pump(tester);
20903
20904                // Passing floating behavior never results in a dy offset of 20
20905                // because the label is not initially floating.
20906                assert_eq!(bottom(tester, LABEL_TEXT), 36.0);
20907                assert_eq!(top(tester, LABEL_TEXT), 20.0);
20908            });
20909        }
20910
20911        // input_decorator_test.dart 'Material2 - InputDecorator hint is displayed when
20912        // floatingLabelBehavior is always'.
20913        #[test]
20914        fn material2_hint_is_displayed_when_the_label_always_floats() {
20915            test_widgets(|tester| {
20916                M2::new(
20917                    InputDecoration::new()
20918                        .floating_label_behavior(FloatingLabelBehavior::Always)
20919                        .hint_text(HINT_TEXT)
20920                        .label_text(LABEL_TEXT),
20921                )
20922                .is_empty(true)
20923                .pump(tester);
20924                tester.pump_and_settle();
20925
20926                assert_eq!(get_opacity(tester, HINT_TEXT), 1.0);
20927            });
20928        }
20929
20930        // input_decorator_test.dart 'Material2 - InputDecorator floating label width scales when
20931        // focused'. Dart reads the clip of the label's ellipsized paragraph; the label's
20932        // width is measured instead: it is the label's constraint, which the clip is in Dart.
20933        #[test]
20934        fn material2_floating_label_width_scales_when_focused() {
20935            test_widgets(|tester| {
20936                let long_string_a: String = "A".repeat(200);
20937                let long_string_b: String = "B".repeat(200);
20938                let pump = |tester: &mut WidgetTester, text: &str, is_focused: bool| {
20939                    let decorator = M2::new(InputDecoration::new().label_text(text))
20940                        .is_empty(true)
20941                        .is_focused(is_focused)
20942                        .build(tester);
20943                    tester.pump_widget(
20944                        waft_widgets::Center::new()
20945                            .child(SizedBox::new().width(100.0).height(100.0).child(decorator))
20946                            .into_widget(),
20947                    );
20948                    tester.pump_and_settle();
20949                };
20950
20951                pump(tester, &long_string_a, false);
20952                let size = tester.get_size(find::text(&long_string_a));
20953                assert_eq!(size, Size::new(100.0, 16.0));
20954
20955                pump(tester, &long_string_b, true);
20956                let size = tester.get_size(find::text(&long_string_b));
20957                // _kFinalLabelScale = 0.75
20958                assert_f32_equals(size.width(), 100.0 / 0.75);
20959                assert_eq!(size.height(), 16.0);
20960            });
20961        }
20962
20963        // input_decorator_test.dart 'Material2 - textAlignVertical can be updated'. The hint keeps
20964        // Dart's string: the case compares its positions only.
20965        #[test]
20966        fn material2_text_align_vertical_can_be_updated() {
20967            test_widgets(|tester| {
20968                // Regression test for https://github.com/flutter/flutter/issues/56933
20969                let alignment: Rc<std::cell::Cell<Option<TextAlignVertical>>> =
20970                    Rc::new(std::cell::Cell::new(Some(TextAlignVertical::TOP)));
20971                let setter: Rc<std::cell::RefCell<Option<waft_widgets::StateSetter>>> =
20972                    Rc::new(std::cell::RefCell::new(None));
20973                let home = {
20974                    let alignment = Rc::clone(&alignment);
20975                    let setter = Rc::clone(&setter);
20976                    waft_widgets::StatefulBuilder::new(move |_app, _context, set_state| {
20977                        *setter.borrow_mut() = Some(set_state);
20978                        let mut decorator =
20979                            InputDecorator::new(InputDecoration::new().hint_text(HINT_TEXT));
20980                        if let Some(alignment) = alignment.get() {
20981                            decorator = decorator.text_align_vertical(alignment);
20982                        }
20983                        decorator.into_widget()
20984                    })
20985                    .into_widget()
20986                };
20987                let theme = m2(&tester.cell.borrow());
20988                tester.pump_widget(material_app(theme, home));
20989                let hint_top = |tester: &WidgetTester| tester.get_rect(find::text(HINT_TEXT)).top;
20990                let set = |tester: &mut WidgetTester, value: Option<TextAlignVertical>| {
20991                    let set_state = setter.borrow().clone().expect("built");
20992                    let alignment = Rc::clone(&alignment);
20993                    set_state(&mut tester.cell.borrow_mut(), &mut move |_app| {
20994                        alignment.set(value)
20995                    });
20996                    tester.pump();
20997                };
20998
20999                let top_position = hint_top(tester);
21000
21001                set(tester, Some(TextAlignVertical::BOTTOM));
21002                assert!(hint_top(tester) > top_position);
21003
21004                // Setting textAlignVertical back to null works and reverts to the default.
21005                set(tester, None);
21006                assert_eq!(hint_top(tester), top_position);
21007            });
21008        }
21009
21010        // input_decorator_test.dart 'Material2 - InputDecorationThemeData.floatingLabelStyle
21011        // overrides label widget styles when the widget is a text widget (focused)'.
21012        #[test]
21013        fn material2_theme_floating_label_style_styles_a_label_widget() {
21014            test_widgets(|tester| {
21015                let floating_label_style = TextStyle::new()
21016                    .font_size(16.0)
21017                    .merge(Some(&TextStyle::new().color(Colors::INDIGO.primary())));
21018                M2::new(InputDecoration::new().label_text(LABEL_TEXT))
21019                    .is_empty(true)
21020                    .is_focused(true) // Label appears floating above input field.
21021                    .input_decoration_theme(
21022                        InputDecorationThemeData::new()
21023                            .floating_label_style(floating_label_style.clone()),
21024                    )
21025                    .pump(tester);
21026
21027                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
21028                assert_eq!(top(tester, LABEL_TEXT), 12.0);
21029                assert_eq!(bottom(tester, LABEL_TEXT), 24.0);
21030                assert_eq!(get_border_bottom(tester), 56.0);
21031                assert_eq!(get_border_weight(tester), 2.0);
21032
21033                // Verify that the styles were passed along
21034                assert_eq!(
21035                    color_of(&get_label_style(tester)),
21036                    color_of(&floating_label_style)
21037                );
21038            });
21039        }
21040
21041        // input_decorator_test.dart 'Material2 - InputDecorationThemeData.labelStyle overrides label
21042        // widget styles when the widget is a text widget'.
21043        #[test]
21044        fn material2_theme_label_style_styles_a_label_widget() {
21045            test_widgets(|tester| {
21046                let label_style = TextStyle::new()
21047                    .font_size(16.0)
21048                    .merge(Some(&TextStyle::new().color(Colors::PURPLE.primary())));
21049                M2::new(InputDecoration::new().label_text(LABEL_TEXT))
21050                    .is_empty(true) // Label appears inline, on top of the input field.
21051                    .input_decoration_theme(
21052                        InputDecorationThemeData::new().label_style(label_style.clone()),
21053                    )
21054                    .pump(tester);
21055
21056                assert_eq!(decorator_size(tester), Size::new(800.0, 56.0));
21057                assert_eq!(top(tester, LABEL_TEXT), 20.0);
21058                assert_eq!(bottom(tester, LABEL_TEXT), 36.0);
21059                assert_eq!(get_border_bottom(tester), 56.0);
21060                assert_eq!(get_border_weight(tester), 1.0);
21061
21062                // Verify that the styles were passed along
21063                assert_eq!(color_of(&get_label_style(tester)), color_of(&label_style));
21064            });
21065        }
21066
21067        // input_decorator_test.dart 'Material2 - prefixIcon in RTL with asymmetric padding'.
21068        #[test]
21069        fn material2_prefix_icon_in_rtl_with_asymmetric_padding_stays_inside() {
21070            test_widgets(|tester| {
21071                // Regression test for https://github.com/flutter/flutter/issues/129591
21072                M2::new(
21073                    InputDecoration::new()
21074                        .content_padding(EdgeInsetsGeometry::from(EdgeInsetsDirectional::only(
21075                            0.0, 0.0, 24.0, 0.0,
21076                        )))
21077                        .prefix_icon(waft_widgets::Focus::new(Icon::new(Some(Icons::search())))),
21078                )
21079                .text_direction(TextDirection::Rtl)
21080                .pump(tester);
21081                tester.pump_and_settle();
21082
21083                expect(
21084                    tester,
21085                    &find::by_type::<InputDecorator>(),
21086                    finds_one_widget(),
21087                );
21088                expect(tester, &find::by_type::<Icon>(), finds_one_widget());
21089
21090                let decorator_right = get_decorator_rect(tester).right;
21091                let prefix_right = tester.get_rect(find::by_type::<Icon>()).right;
21092
21093                // The prefix is inside the decorator.
21094                assert!(decorator_right <= prefix_right);
21095            });
21096        }
21097
21098        // input_decorator_test.dart 'Material2 - intrinsic width with prefixIcon/suffixIcon'.
21099        #[test]
21100        fn material2_intrinsic_width_with_prefix_and_suffix_icons_keeps_the_text_width() {
21101            test_widgets(|tester| {
21102                // Regression test for https://github.com/flutter/flutter/issues/137937
21103                for direction in [TextDirection::Rtl, TextDirection::Ltr] {
21104                    let mut measure_text = |decoration: InputDecoration| {
21105                        M2::new(decoration)
21106                            .use_intrinsic_width(true)
21107                            .text_direction(direction)
21108                            .pump(tester);
21109                        tester.pump_and_settle();
21110                        expect(tester, &find::text(INPUT_TEXT), finds_one_widget());
21111                        tester.get_rect(find::text(INPUT_TEXT)).size()
21112                    };
21113                    let padding = || EdgeInsetsDirectional::only(12.0, 0.0, 24.0, 0.0);
21114                    let icon =
21115                        || waft_widgets::Focus::new(Icon::new(Some(Icons::search()))).into_widget();
21116
21117                    let without_icons = measure_text(
21118                        InputDecoration::new().content_padding(EdgeInsetsGeometry::from(padding())),
21119                    );
21120                    let with_prefix_icon = measure_text(
21121                        InputDecoration::new()
21122                            .content_padding(EdgeInsetsGeometry::from(padding()))
21123                            .prefix_icon(icon()),
21124                    );
21125                    let with_suffix_icon = measure_text(
21126                        InputDecoration::new()
21127                            .content_padding(EdgeInsetsGeometry::from(padding()))
21128                            .suffix_icon(icon()),
21129                    );
21130
21131                    assert_eq!(
21132                        with_prefix_icon.width(),
21133                        without_icons.width(),
21134                        "text width is different with prefixIcon and {direction:?}"
21135                    );
21136                    assert_eq!(
21137                        with_suffix_icon.width(),
21138                        without_icons.width(),
21139                        "text width is different with prefixIcon and {direction:?}"
21140                    );
21141                }
21142            });
21143        }
21144
21145        // input_decorator_test.dart 'UnderlineInputBorder with BorderStyle.none should not show
21146        // anything'.
21147        #[test]
21148        fn an_underline_border_with_no_style_paints_no_ring() {
21149            test_widgets(|tester| {
21150                // Regression test for https://github.com/flutter/flutter/issues/143746
21151                tester.pump_widget(
21152                    BuildInputDecorator::new(
21153                        InputDecoration::new().enabled_border(
21154                            UnderlineInputBorder::new()
21155                                .border_side(BorderSide {
21156                                    style: waft_painting::BorderStyle::None,
21157                                    ..BorderSide::default()
21158                                })
21159                                .border_radius(BorderRadius::all(waft_embedder::Radius::circular(
21160                                    4.0,
21161                                ))),
21162                        ),
21163                    )
21164                    .build(),
21165                );
21166                assert!(paints(&decorator_ops(tester), &[PaintCall::drrect(None)]).is_err());
21167            });
21168        }
21169
21170        // input_decorator_test.dart 'InputDecorator _buildError with errorText correctly updates on
21171        // BuildContext updates'. The decoration changes through a new pump where Dart's
21172        // `ValueListenableBuilder` rebuilds; both update the decorator with a new decoration.
21173        #[test]
21174        fn the_error_text_updates_when_the_decoration_changes() {
21175            test_widgets(|tester| {
21176                const HELPER_TEXT_VALUE: &str = "helper text";
21177                let pump = |tester: &mut WidgetTester, value: Option<&str>| {
21178                    let mut decoration = InputDecoration::new().helper_text(HELPER_TEXT_VALUE);
21179                    if let Some(value) = value {
21180                        decoration = decoration.error_text(value);
21181                    }
21182                    tester.pump_widget(BuildInputDecorator::new(decoration).build());
21183                    tester.pump_and_settle();
21184                };
21185                pump(tester, Some("initial error"));
21186
21187                expect(tester, &find::text("initial error"), finds_one_widget());
21188                expect(tester, &find::text(HELPER_TEXT_VALUE), finds_nothing());
21189
21190                pump(tester, None);
21191
21192                expect(tester, &find::text("initial error"), finds_nothing());
21193                expect(tester, &find::text(HELPER_TEXT_VALUE), finds_one_widget());
21194            });
21195        }
21196
21197        /// Dart's `MaterialApp(theme:, home: Scaffold(body: Directionality(textDirection:,
21198        /// child: SizedBox(width:, child: InputDecorator(decoration:)))))` of the supporting text
21199        /// padding cases.
21200        fn pump_in_scaffold(
21201            tester: &mut WidgetTester,
21202            theme: fn(&App) -> ThemeData,
21203            direction: TextDirection,
21204            width: f64,
21205            decoration: InputDecoration,
21206        ) {
21207            let theme = theme(&tester.cell.borrow());
21208            let home = crate::scaffold::Scaffold::new().body(Directionality::new(
21209                direction,
21210                SizedBox::new()
21211                    .width(width)
21212                    .child(InputDecorator::new(decoration)),
21213            ));
21214            tester.pump_widget(material_app(theme, home.into_widget()));
21215            tester.pump_and_settle();
21216        }
21217
21218        fn string_rect(tester: &WidgetTester, text: &str) -> Rect {
21219            tester.get_rect(find::text(text))
21220        }
21221
21222        // input_decorator_test.dart 'helper/error text default padding is correct'. The case keeps
21223        // Dart's strings: it reads the edges of a text that wraps to the available width.
21224        #[test]
21225        fn helper_and_error_text_default_padding_is_correct() {
21226            test_widgets(|tester| {
21227                const DEFAULT_PADDING: f64 = 16.0; // From M3 spec.
21228                const LONG_TEXT: &str =
21229                    "This is a very long text that should wrap and fill the available width";
21230                const INPUT_WIDTH: f64 = 300.0;
21231
21232                for direction in [TextDirection::Ltr, TextDirection::Rtl] {
21233                    for error in [false, true] {
21234                        let mut decoration = InputDecoration::new().filled(true);
21235                        decoration = if error {
21236                            decoration.error_text(LONG_TEXT)
21237                        } else {
21238                            decoration.helper_text(LONG_TEXT)
21239                        };
21240                        pump_in_scaffold(tester, m3, direction, INPUT_WIDTH, decoration);
21241                        let rect = string_rect(tester, LONG_TEXT);
21242                        assert_eq!(rect.left, DEFAULT_PADDING, "{direction:?} error: {error}");
21243                        assert_eq!(
21244                            rect.right,
21245                            INPUT_WIDTH - DEFAULT_PADDING,
21246                            "{direction:?} error: {error}"
21247                        );
21248                    }
21249                }
21250            });
21251        }
21252
21253        // input_decorator_test.dart 'InputDecorator does not crash at zero area'.
21254        #[test]
21255        fn the_decorator_does_not_crash_at_zero_area() {
21256            test_widgets(|tester| {
21257                for decoration in [
21258                    InputDecoration::new(),
21259                    InputDecoration::new().border(OutlineInputBorder::new()),
21260                ] {
21261                    let theme = m3(&tester.cell.borrow());
21262                    let home = crate::scaffold::Scaffold::new().body(
21263                        waft_widgets::Center::new()
21264                            .child(SizedBox::shrink().child(InputDecorator::new(decoration))),
21265                    );
21266                    tester.pump_widget(material_app(theme, home.into_widget()));
21267                    assert_eq!(decorator_size(tester), Size::ZERO);
21268                }
21269            });
21270        }
21271
21272        fn supporting_decoration(
21273            error_text: Option<&str>,
21274            helper_text: Option<&str>,
21275            supporting_text_padding: Option<EdgeInsetsGeometry>,
21276        ) -> InputDecoration {
21277            let mut decoration = InputDecoration::new()
21278                .filled(true)
21279                .counter_text(COUNTER_TEXT);
21280            if let Some(error_text) = error_text {
21281                decoration = decoration.error_text(error_text);
21282            }
21283            if let Some(helper_text) = helper_text {
21284                decoration = decoration.helper_text(HELPER_TEXT);
21285                assert_eq!(helper_text, HELPER_TEXT);
21286            }
21287            if let Some(padding) = supporting_text_padding {
21288                decoration = decoration.supporting_text_padding(padding);
21289            }
21290            decoration
21291        }
21292
21293        /// An edge read through the page's transforms, which Waft's f32 `Matrix4` rounds where
21294        /// Dart's doubles do not.
21295        fn edge_eq(actual: f64, expected: f64) {
21296            assert_f32_equals(actual, expected);
21297        }
21298
21299        const INPUT_GAP: f64 = 4.0; // _kInputExtraPadding in Material 3 filled field.
21300
21301        // input_decorator_test.dart 'supportingTextPadding defined in InputDecoration is used for
21302        // supporting text'. An edge at a text's width is a fraction of FlutterTest's letter
21303        // spacing, which the f32 transforms of a position round.
21304        #[test]
21305        fn supporting_text_padding_of_the_decoration_places_the_supporting_text() {
21306            test_widgets(|tester| {
21307                const START: f64 = 32.0;
21308                const END: f64 = 24.0;
21309                const TOP: f64 = 16.0;
21310                const BOTTOM: f64 = 12.0;
21311                const INPUT_WIDTH: f64 = 300.0;
21312                let padding = Some(EdgeInsetsGeometry::directional(START, 0.0, END, 0.0));
21313
21314                // Calculate default vertical bounds first to ensure new vertical padding shifts
21315                // correctly.
21316                pump_in_scaffold(
21317                    tester,
21318                    m3,
21319                    TextDirection::Ltr,
21320                    INPUT_WIDTH,
21321                    supporting_decoration(Some(ERROR_TEXT), None, None),
21322                );
21323                let default_error_dy = string_rect(tester, ERROR_TEXT).top;
21324                let default_total_height = decorator_size(tester).height();
21325
21326                // LTR with custom supportingTextPadding (error).
21327                pump_in_scaffold(
21328                    tester,
21329                    m3,
21330                    TextDirection::Ltr,
21331                    INPUT_WIDTH,
21332                    supporting_decoration(
21333                        Some(ERROR_TEXT),
21334                        None,
21335                        Some(EdgeInsetsGeometry::directional(START, TOP, END, BOTTOM)),
21336                    ),
21337                );
21338                edge_eq(string_rect(tester, ERROR_TEXT).left, START + INPUT_GAP);
21339                edge_eq(
21340                    string_rect(tester, COUNTER_TEXT).right,
21341                    INPUT_WIDTH - END - INPUT_GAP,
21342                );
21343
21344                // Verify vertical padding shift.
21345                assert!(string_rect(tester, ERROR_TEXT).top > default_error_dy);
21346                assert!(decorator_size(tester).height() > default_total_height);
21347
21348                // RTL with custom supportingTextPadding (error).
21349                pump_in_scaffold(
21350                    tester,
21351                    m3,
21352                    TextDirection::Rtl,
21353                    INPUT_WIDTH,
21354                    supporting_decoration(Some(ERROR_TEXT), None, padding),
21355                );
21356                // In RTL, "start" is from the right, so errorText is placed on the right.
21357                edge_eq(
21358                    string_rect(tester, ERROR_TEXT).right,
21359                    INPUT_WIDTH - START - INPUT_GAP,
21360                );
21361                // In RTL, "end" is from the left, so counterText is placed on the left.
21362                edge_eq(string_rect(tester, COUNTER_TEXT).left, END + INPUT_GAP);
21363
21364                // LTR with custom supportingTextPadding (helper).
21365                pump_in_scaffold(
21366                    tester,
21367                    m3,
21368                    TextDirection::Ltr,
21369                    INPUT_WIDTH,
21370                    supporting_decoration(None, Some(HELPER_TEXT), padding),
21371                );
21372                edge_eq(string_rect(tester, HELPER_TEXT).left, START + INPUT_GAP);
21373                edge_eq(
21374                    string_rect(tester, COUNTER_TEXT).right,
21375                    INPUT_WIDTH - END - INPUT_GAP,
21376                );
21377
21378                // RTL with custom supportingTextPadding (helper).
21379                pump_in_scaffold(
21380                    tester,
21381                    m3,
21382                    TextDirection::Rtl,
21383                    INPUT_WIDTH,
21384                    supporting_decoration(None, Some(HELPER_TEXT), padding),
21385                );
21386                edge_eq(
21387                    string_rect(tester, HELPER_TEXT).right,
21388                    INPUT_WIDTH - START - INPUT_GAP,
21389                );
21390                edge_eq(string_rect(tester, COUNTER_TEXT).left, END + INPUT_GAP);
21391            });
21392        }
21393
21394        fn theme_with_supporting_text_padding(app: &App) -> ThemeData {
21395            ThemeData::builder()
21396                .use_material3(true)
21397                .input_decoration_theme(
21398                    InputDecorationThemeData::new().supporting_text_padding(
21399                        EdgeInsetsGeometry::directional(40.0, 0.0, 20.0, 0.0),
21400                    ),
21401                )
21402                .build(app)
21403        }
21404
21405        // input_decorator_test.dart 'supportingTextPadding defined in InputDecorationTheme is used
21406        // for supporting text'.
21407        #[test]
21408        fn supporting_text_padding_of_the_theme_places_the_supporting_text() {
21409            test_widgets(|tester| {
21410                const THEME_START: f64 = 40.0;
21411                const THEME_END: f64 = 20.0;
21412                const INPUT_WIDTH: f64 = 300.0;
21413                for (error, helper) in [(Some(ERROR_TEXT), None), (None, Some(HELPER_TEXT))] {
21414                    let text = error.or(helper).expect("one of them");
21415                    pump_in_scaffold(
21416                        tester,
21417                        theme_with_supporting_text_padding,
21418                        TextDirection::Ltr,
21419                        INPUT_WIDTH,
21420                        supporting_decoration(error, helper, None),
21421                    );
21422                    edge_eq(string_rect(tester, text).left, THEME_START + INPUT_GAP);
21423                    edge_eq(
21424                        string_rect(tester, COUNTER_TEXT).right,
21425                        INPUT_WIDTH - THEME_END - INPUT_GAP,
21426                    );
21427
21428                    // In RTL, "start" is from the right, "end" is from the left.
21429                    pump_in_scaffold(
21430                        tester,
21431                        theme_with_supporting_text_padding,
21432                        TextDirection::Rtl,
21433                        INPUT_WIDTH,
21434                        supporting_decoration(error, helper, None),
21435                    );
21436                    edge_eq(
21437                        string_rect(tester, text).right,
21438                        INPUT_WIDTH - THEME_START - INPUT_GAP,
21439                    );
21440                    edge_eq(
21441                        string_rect(tester, COUNTER_TEXT).left,
21442                        THEME_END + INPUT_GAP,
21443                    );
21444                }
21445            });
21446        }
21447
21448        // input_decorator_test.dart 'supportingTextPadding with an icon positions supporting text
21449        // correctly in LTR and RTL'.
21450        #[test]
21451        fn supporting_text_padding_with_an_icon_shifts_only_the_start() {
21452            test_widgets(|tester| {
21453                const INPUT_WIDTH: f64 = 300.0;
21454                let pump =
21455                    |tester: &mut WidgetTester, direction: TextDirection, with_icon: bool| {
21456                        let mut decoration = supporting_decoration(
21457                            Some(ERROR_TEXT),
21458                            None,
21459                            Some(EdgeInsetsGeometry::directional(32.0, 0.0, 24.0, 0.0)),
21460                        );
21461                        if with_icon {
21462                            decoration = decoration.icon(SizedBox::new().width(24.0).height(24.0));
21463                        }
21464                        pump_in_scaffold(tester, m3, direction, INPUT_WIDTH, decoration);
21465                    };
21466
21467                // Measure baseline start/end offsets without icon in LTR.
21468                pump(tester, TextDirection::Ltr, false);
21469                let ltr_start_without_icon = string_rect(tester, ERROR_TEXT).left;
21470                let ltr_end_without_icon = string_rect(tester, COUNTER_TEXT).right;
21471
21472                // With icon in LTR: start offset increases by _boxSize(icon).width; end is
21473                // unaffected.
21474                pump(tester, TextDirection::Ltr, true);
21475                let ltr_start_with_icon = string_rect(tester, ERROR_TEXT).left;
21476                let ltr_end_with_icon = string_rect(tester, COUNTER_TEXT).right;
21477                // The delta is the actual _boxSize(icon).width added by the layout.
21478                let icon_box_width = ltr_start_with_icon - ltr_start_without_icon;
21479                assert!(icon_box_width > 0.0); // Icon shifts start offset right in LTR.
21480                assert_eq!(ltr_end_with_icon, ltr_end_without_icon); // End (counter) is unaffected by icon.
21481
21482                // Measure baseline start/end offsets without icon in RTL.
21483                pump(tester, TextDirection::Rtl, false);
21484                let rtl_start_without_icon = string_rect(tester, ERROR_TEXT).right;
21485                let rtl_end_without_icon = string_rect(tester, COUNTER_TEXT).left;
21486
21487                // With icon in RTL: start offset decreases by _boxSize(icon).width; end is
21488                // unaffected.
21489                pump(tester, TextDirection::Rtl, true);
21490                let rtl_start_with_icon = string_rect(tester, ERROR_TEXT).right;
21491                let rtl_end_with_icon = string_rect(tester, COUNTER_TEXT).left;
21492                // In RTL the icon is on the right, so it reduces the start offset from the right.
21493                assert_eq!(rtl_start_without_icon - rtl_start_with_icon, icon_box_width);
21494                assert_eq!(rtl_end_with_icon, rtl_end_without_icon); // End (counter) is unaffected by icon.
21495            });
21496        }
21497
21498        // input_decorator_test.dart 'supportingTextPadding in Material 2 (the 8.0 gap)'.
21499        #[test]
21500        fn supporting_text_padding_in_material2_replaces_the_8_gap() {
21501            test_widgets(|tester| {
21502                let pump = |tester: &mut WidgetTester,
21503                            padding: Option<EdgeInsetsGeometry>,
21504                            error_text: Option<&str>,
21505                            helper_text: Option<&str>| {
21506                    let mut decoration = InputDecoration::new().filled(true);
21507                    if let Some(error_text) = error_text {
21508                        decoration = decoration.error_text(error_text);
21509                    }
21510                    if let Some(helper_text) = helper_text {
21511                        decoration = decoration.helper_text(helper_text);
21512                    }
21513                    if let Some(padding) = padding {
21514                        decoration = decoration.supporting_text_padding(padding);
21515                    }
21516                    let theme = m2(&tester.cell.borrow());
21517                    let home = crate::scaffold::Scaffold::new().body(
21518                        waft_widgets::Align::new()
21519                            .alignment(waft_painting::AlignmentGeometry::Alignment(
21520                                waft_painting::Alignment::TOP_LEFT,
21521                            ))
21522                            .child(
21523                                SizedBox::new()
21524                                    .width(300.0)
21525                                    .child(InputDecorator::new(decoration)),
21526                            ),
21527                    );
21528                    tester.pump_widget(material_app(theme, home.into_widget()));
21529                    tester.pump_and_settle();
21530                };
21531                let gap = |tester: &WidgetTester, text: &str| {
21532                    string_rect(tester, text).top - get_border_bottom(tester)
21533                };
21534
21535                // Default Material 2 behavior: gap between container bottom and helper text is 8.0.
21536                pump(tester, None, None, Some(HELPER_TEXT));
21537                assert_eq!(gap(tester, HELPER_TEXT), 8.0);
21538
21539                // Default Material 2 behavior: gap between container bottom and error text is 8.0.
21540                pump(tester, None, Some(ERROR_TEXT), None);
21541                assert_eq!(gap(tester, ERROR_TEXT), 8.0);
21542
21543                // Custom supportingTextPadding with explicit top overrides the 8.0 gap.
21544                const CUSTOM_TOP_PADDING: f64 = 16.0;
21545                pump(
21546                    tester,
21547                    Some(EdgeInsetsGeometry::directional(
21548                        0.0,
21549                        CUSTOM_TOP_PADDING,
21550                        0.0,
21551                        0.0,
21552                    )),
21553                    None,
21554                    Some(HELPER_TEXT),
21555                );
21556                assert_eq!(gap(tester, HELPER_TEXT), CUSTOM_TOP_PADDING);
21557
21558                // Custom supportingTextPadding with only horizontal padding removes the 8.0 gap
21559                // (top defaults to 0.0).
21560                pump(
21561                    tester,
21562                    Some(EdgeInsetsGeometry::directional(24.0, 0.0, 0.0, 0.0)),
21563                    None,
21564                    Some(HELPER_TEXT),
21565                );
21566                assert_eq!(gap(tester, HELPER_TEXT), 0.0);
21567            });
21568        }
21569
21570        // input_decorator_test.dart 'InputDecorator respects individual text directions for label and
21571        // hint'.
21572        #[test]
21573        fn the_label_and_hint_take_their_own_text_directions() {
21574            test_widgets(|tester| {
21575                const HINT: &str = "Hint Text";
21576                const LABEL: &str = "Label Text";
21577                let theme = m3(&tester.cell.borrow());
21578                let home = crate::scaffold::Scaffold::new().body(Directionality::new(
21579                    TextDirection::Ltr,
21580                    waft_widgets::Center::new().child(
21581                        InputDecorator::new(
21582                            InputDecoration::new()
21583                                .hint_text(HINT)
21584                                .label_text(LABEL)
21585                                .label_text_direction(TextDirection::Rtl)
21586                                .hint_text_direction(TextDirection::Rtl),
21587                        )
21588                        .is_empty(true)
21589                        .child(SizedBox::shrink()),
21590                    ),
21591                ));
21592                tester.pump_widget(material_app(theme, home.into_widget()));
21593
21594                let direction_of = |text: &str| {
21595                    let element = tester.element(find::text(text));
21596                    tester.widget(element, |text: &waft_widgets::Text| text.text_direction)
21597                };
21598                assert_eq!(direction_of(HINT), Some(TextDirection::Rtl));
21599                assert_eq!(direction_of(LABEL), Some(TextDirection::Rtl));
21600            });
21601        }
21602
21603        /// Dart's 'Floating label hit test matches its painted position (textDirection)'.
21604        fn check_floating_label_hit_test(tester: &mut WidgetTester, text_direction: TextDirection) {
21605            let tap_count = Rc::new(std::cell::Cell::new(0));
21606            let label_key = GlobalKey::new();
21607            let on_tap = {
21608                let tap_count = Rc::clone(&tap_count);
21609                waft_foundation::Listener::new(move |_app| tap_count.set(tap_count.get() + 1))
21610            };
21611            tester.pump_widget(
21612                BuildInputDecorator::new(
21613                    InputDecoration::new()
21614                        .border(OutlineInputBorder::new())
21615                        .label(
21616                            waft_widgets::GestureDetector::new()
21617                                .key(label_key.clone().into())
21618                                .behavior(waft_rendering::HitTestBehavior::Opaque)
21619                                .on_tap(on_tap)
21620                                .child(SizedBox::new().width(100.0).height(20.0)),
21621                        ),
21622                )
21623                .text_direction(text_direction)
21624                .build(),
21625            );
21626
21627            // The label floats (isEmpty is false), so it is painted scaled and moved up
21628            // onto the border, above its layout position.
21629            let label_rect = key_rect(tester, &label_key);
21630            assert_eq!(label_rect.width(), 75.0);
21631
21632            // Taps at the painted label hit the label.
21633            tester.tap_at(label_rect.center(), 1);
21634            tester.tap_at(label_rect.bottom_left() + Offset::new(1.0, -1.0), 2);
21635            assert_eq!(tap_count.get(), 2);
21636
21637            // A tap below the painted label, inside its layout position, misses the label.
21638            tester.tap_at(label_rect.bottom_center() + Offset::new(0.0, 10.0), 3);
21639            assert_eq!(tap_count.get(), 2);
21640        }
21641
21642        // input_decorator_test.dart 'Floating label hit test matches its painted position
21643        // (TextDirection.rtl)'.
21644        #[test]
21645        fn the_floating_label_is_hit_where_it_is_painted_rtl() {
21646            test_widgets(|tester| check_floating_label_hit_test(tester, TextDirection::Rtl));
21647        }
21648
21649        // input_decorator_test.dart 'Floating label hit test matches its painted position
21650        // (TextDirection.ltr)'.
21651        #[test]
21652        fn the_floating_label_is_hit_where_it_is_painted_ltr() {
21653            test_widgets(|tester| check_floating_label_hit_test(tester, TextDirection::Ltr));
21654        }
21655
21656        // input_decorator_test.dart 'InputDecorator.debugDescribeChildren' (Material 2).
21657        #[test]
21658        fn a_material_2_decoration_describes_its_children_by_slot() {
21659            test_widgets(|tester| {
21660                M2::new(
21661                    InputDecoration::new()
21662                        .icon(Text::new("icon"))
21663                        .label_text("label")
21664                        .hint_text("hint")
21665                        .prefix_text("prefix")
21666                        .suffix_text("suffix")
21667                        .prefix_icon(Text::new("prefixIcon"))
21668                        .suffix_icon(Text::new("suffixIcon"))
21669                        .helper_text("helper")
21670                        .counter_text("counter"),
21671                )
21672                .child(Text::new("text"))
21673                .pump(tester);
21674
21675                let decoration = tester
21676                    .render_object(find::by_type::<InputDecorator>())
21677                    .downcast::<RenderDecoration>(&tester.cell.borrow())
21678                    .expect("the decorator's render object");
21679                let names: Vec<String> = {
21680                    let app = tester.cell.borrow();
21681                    decoration
21682                        .as_object()
21683                        .to_diagnostics_node(&app, None)
21684                        .children()
21685                        .iter()
21686                        .map(|node| node.name().expect("a named child").to_owned())
21687                        .collect()
21688                };
21689                assert_eq!(
21690                    names,
21691                    [
21692                        "icon",
21693                        "input",
21694                        "prefixIcon",
21695                        "suffixIcon",
21696                        "prefix",
21697                        "suffix",
21698                        "label",
21699                        "hint",
21700                        "helperError",
21701                        "counter",
21702                        "container",
21703                    ]
21704                );
21705            });
21706        }
21707    }
21708    /// `input_decorator_test.dart`, "InputDecorationThemeData implements
21709    /// debugFillDescription". Colors print as the `Color` the port stores, not as Dart's
21710    /// `MaterialColor`.
21711    #[test]
21712    fn an_input_decoration_theme_data_describes_its_properties() {
21713        use waft_embedder::Color;
21714        use waft_foundation::{DiagnosticPropertiesBuilder, Diagnosticable};
21715        use waft_painting::{BorderSide, EdgeInsetsDirectional, TextStyle};
21716        use waft_rendering::BoxConstraints;
21717
21718        use crate::input_border::UnderlineInputBorder;
21719        use crate::{FloatingLabelAlignment, FloatingLabelBehavior, InputDecorationThemeData};
21720
21721        let red = Color::new(0xfff44336);
21722        let blue = Color::new(0xff2196f3);
21723        let green = Color::new(0xff4caf50);
21724        let constraints = BoxConstraints::new()
21725            .min_width(10.0)
21726            .max_width(10.0)
21727            .min_height(30.0)
21728            .max_height(30.0);
21729        let theme = InputDecorationThemeData::new()
21730            .label_style(TextStyle::new())
21731            .floating_label_style(TextStyle::new())
21732            .helper_style(TextStyle::new())
21733            .helper_max_lines(6)
21734            .hint_style(TextStyle::new())
21735            .error_style(TextStyle::new())
21736            .error_max_lines(5)
21737            .floating_label_behavior(FloatingLabelBehavior::Never)
21738            .floating_label_alignment(FloatingLabelAlignment::CENTER)
21739            .is_dense(true)
21740            .content_padding(EdgeInsetsDirectional::only(40.0, 12.0, 0.0, 12.0))
21741            .is_collapsed(true)
21742            .icon_color(red)
21743            .prefix_icon_color(blue)
21744            .prefix_icon_constraints(constraints)
21745            .prefix_style(TextStyle::new())
21746            .suffix_icon_color(blue)
21747            .suffix_icon_constraints(constraints)
21748            .suffix_style(TextStyle::new())
21749            .counter_style(TextStyle::new())
21750            .filled(true)
21751            .fill_color(red)
21752            .active_indicator_border(BorderSide::default())
21753            .outline_border(BorderSide::default())
21754            .focus_color(blue)
21755            .hover_color(green)
21756            .error_border(UnderlineInputBorder::new())
21757            .focused_border(UnderlineInputBorder::new())
21758            .focused_error_border(UnderlineInputBorder::new())
21759            .disabled_border(UnderlineInputBorder::new())
21760            .enabled_border(UnderlineInputBorder::new())
21761            .border(UnderlineInputBorder::new())
21762            .align_label_with_hint(true)
21763            .constraints(constraints);
21764        let description: Vec<String> = waft_widgets::testing::describe_properties(
21765            |properties: &mut DiagnosticPropertiesBuilder| theme.debug_fill_properties(properties),
21766        );
21767        assert_eq!(
21768            description,
21769            [
21770                "labelStyle: TextStyle(<all styles inherited>)".to_string(),
21771                "floatingLabelStyle: TextStyle(<all styles inherited>)".to_string(),
21772                "helperStyle: TextStyle(<all styles inherited>)".to_string(),
21773                "helperMaxLines: 6".to_string(),
21774                "hintStyle: TextStyle(<all styles inherited>)".to_string(),
21775                "errorStyle: TextStyle(<all styles inherited>)".to_string(),
21776                "errorMaxLines: 5".to_string(),
21777                "floatingLabelBehavior: FloatingLabelBehavior.never".to_string(),
21778                "floatingLabelAlignment: FloatingLabelAlignment.center".to_string(),
21779                "isDense: true".to_string(),
21780                "contentPadding: EdgeInsetsDirectional(40.0, 12.0, 0.0, 12.0)".to_string(),
21781                "isCollapsed: true".to_string(),
21782                format!("iconColor: {red}"),
21783                format!("prefixIconColor: {blue}"),
21784                "prefixIconConstraints: BoxConstraints(w=10.0, h=30.0)".to_string(),
21785                "prefixStyle: TextStyle(<all styles inherited>)".to_string(),
21786                format!("suffixIconColor: {blue}"),
21787                "suffixIconConstraints: BoxConstraints(w=10.0, h=30.0)".to_string(),
21788                "suffixStyle: TextStyle(<all styles inherited>)".to_string(),
21789                "counterStyle: TextStyle(<all styles inherited>)".to_string(),
21790                "filled: true".to_string(),
21791                format!("fillColor: {red}"),
21792                "activeIndicatorBorder: BorderSide".to_string(),
21793                "outlineBorder: BorderSide".to_string(),
21794                format!("focusColor: {blue}"),
21795                format!("hoverColor: {green}"),
21796                "errorBorder: UnderlineInputBorder()".to_string(),
21797                "focusedBorder: UnderlineInputBorder()".to_string(),
21798                "focusedErrorBorder: UnderlineInputBorder()".to_string(),
21799                "disabledBorder: UnderlineInputBorder()".to_string(),
21800                "enabledBorder: UnderlineInputBorder()".to_string(),
21801                "border: UnderlineInputBorder()".to_string(),
21802                "alignLabelWithHint: true".to_string(),
21803                "constraints: BoxConstraints(w=10.0, h=30.0)".to_string(),
21804            ]
21805        );
21806    }
21807}