Skip to main content

waft_material/
divider.rs

1//! Flutter counterpart: material_ui's `divider.dart`.
2
3use waft_embedder::Color;
4use waft_foundation::App;
5use waft_painting::{Border, BorderRadiusGeometry, BorderSide, BoxDecoration, EdgeInsetsGeometry};
6use waft_widgets::{
7    BuildContext, Center, Container, IntoWidget, KeyRef, SizedBox, StatelessWidget, WidgetRef,
8};
9
10use crate::divider_theme::{DividerTheme, DividerThemeData, DividerThemeDataGetters};
11use crate::generated::divider_defaults_m3::DividerDefaultsM3;
12use crate::theme::Theme;
13
14/// A thin horizontal line, with padding on either side.
15///
16/// In the Material Design language, this represents a divider. Dividers can be
17/// used in lists, `Drawer`s, and elsewhere to separate content.
18///
19/// To create a divider between `ListTile` items, consider using
20/// `ListTile::divide_tiles`, which is optimized for this case.
21///
22/// The box's total height is controlled by [`height`](Self::height). The appropriate
23/// padding is automatically computed from the height.
24///
25/// See also:
26///
27///  * `PopupMenuDivider`, which is the equivalent but for popup menus.
28///  * `ListTile::divide_tiles`, another approach to dividing widgets in a list.
29///  * [`VerticalDivider`], which is the vertical analog of this widget.
30///  * <https://material.io/design/components/dividers.html>
31#[derive(Debug, Default)]
32pub struct Divider {
33    pub key: Option<KeyRef>,
34
35    /// The divider's height extent.
36    ///
37    /// The divider itself is always drawn as a horizontal line that is centered
38    /// within the height specified by this value.
39    ///
40    /// If this is null, then the [`DividerThemeData::space`] is used. If that is
41    /// also null, then this defaults to 16.0.
42    pub height: Option<f64>,
43
44    /// The thickness of the line drawn within the divider.
45    ///
46    /// A divider with a [`thickness`](Self::thickness) of 0.0 is always drawn as a line with a
47    /// height of exactly one device pixel.
48    ///
49    /// If this is null, then the [`DividerThemeData::thickness`] is used. If
50    /// that is also null, then this defaults to 0.0.
51    pub thickness: Option<f64>,
52
53    /// The amount of empty space to the leading edge of the divider.
54    ///
55    /// If this is null, then the [`DividerThemeData::indent`] is used. If that is
56    /// also null, then this defaults to 0.0.
57    pub indent: Option<f64>,
58
59    /// The amount of empty space to the trailing edge of the divider.
60    ///
61    /// If this is null, then the [`DividerThemeData::end_indent`] is used. If that is
62    /// also null, then this defaults to 0.0.
63    pub end_indent: Option<f64>,
64
65    /// The amount of radius for the border of the divider.
66    ///
67    /// If this is null, then [`DividerThemeData::radius`] is used. If that is
68    /// also null, then the default radius of `BoxDecoration` is used.
69    pub radius: Option<BorderRadiusGeometry>,
70
71    /// The color to use when painting the line.
72    ///
73    /// If this is null, then the [`DividerThemeData::color`] is used. If that is
74    /// also null, then this defaults to `ColorScheme::outline_variant`, or to
75    /// `ThemeData::divider_color` if `ThemeData::use_material3` is false.
76    pub color: Option<Color>,
77}
78
79impl Divider {
80    /// Creates a Material Design divider.
81    ///
82    /// The [`height`](Self::height), [`thickness`](Self::thickness), [`indent`](Self::indent),
83    /// and [`end_indent`](Self::end_indent) must be null or non-negative. Dart's optional named
84    /// arguments are the fluent setters.
85    pub fn new() -> Divider {
86        Divider::default()
87    }
88
89    /// Dart `Divider(key:)`.
90    pub fn key(mut self, key: KeyRef) -> Divider {
91        self.key = Some(key);
92        self
93    }
94
95    /// Dart `Divider(height:)`.
96    pub fn height(mut self, height: f64) -> Divider {
97        debug_assert!(height >= 0.0);
98        self.height = Some(height);
99        self
100    }
101
102    /// Dart `Divider(thickness:)`.
103    pub fn thickness(mut self, thickness: f64) -> Divider {
104        debug_assert!(thickness >= 0.0);
105        self.thickness = Some(thickness);
106        self
107    }
108
109    /// Dart `Divider(indent:)`.
110    pub fn indent(mut self, indent: f64) -> Divider {
111        debug_assert!(indent >= 0.0);
112        self.indent = Some(indent);
113        self
114    }
115
116    /// Dart `Divider(endIndent:)`.
117    pub fn end_indent(mut self, end_indent: f64) -> Divider {
118        debug_assert!(end_indent >= 0.0);
119        self.end_indent = Some(end_indent);
120        self
121    }
122
123    /// Dart `Divider(radius:)`.
124    pub fn radius(mut self, radius: impl Into<BorderRadiusGeometry>) -> Divider {
125        self.radius = Some(radius.into());
126        self
127    }
128
129    /// Dart `Divider(color:)`.
130    pub fn color(mut self, color: Color) -> Divider {
131        self.color = Some(color);
132        self
133    }
134
135    /// Computes the [`BorderSide`] that represents a divider.
136    ///
137    /// If `color` is null, then [`DividerThemeData::color`] is used. If that is also
138    /// null, then if `ThemeData::use_material3` is true then it defaults to
139    /// `ThemeData::color_scheme`'s `ColorScheme::outline_variant`. Otherwise
140    /// `ThemeData::divider_color` is used.
141    ///
142    /// If `width` is null, then [`DividerThemeData::thickness`] is used. If that is
143    /// also null, then this defaults to 0.0 (a hairline border).
144    ///
145    /// If `context` is null, the default color of [`BorderSide`] is used and the
146    /// default width of 0.0 is used.
147    ///
148    /// This example uses this method to create a box that has a divider above and
149    /// below it. This is sometimes useful with lists, for instance, to separate a
150    /// scrollable section from the rest of the interface.
151    ///
152    /// ```text
153    /// DecoratedBox::new(BoxDecoration::new().border(Border {
154    ///     top: Divider::create_border_side(app, Some(context), None, None),
155    ///     bottom: Divider::create_border_side(app, Some(context), None, None),
156    ///     ..Border::default()
157    /// }))
158    /// ```
159    pub fn create_border_side(
160        app: &mut App,
161        context: Option<BuildContext>,
162        color: Option<Color>,
163        width: Option<f64>,
164    ) -> BorderSide {
165        let divider_theme = context.map(|context| DividerTheme::of(app, context));
166        let defaults = context.map(|context| divider_defaults(app, context));
167        let effective_color = color
168            .or(divider_theme.as_ref().and_then(|theme| theme.color))
169            .or_else(|| defaults.as_ref().and_then(|defaults| defaults.color(app)));
170        let effective_width = width
171            .or(divider_theme.as_ref().and_then(|theme| theme.thickness))
172            .or_else(|| {
173                defaults
174                    .as_ref()
175                    .and_then(|defaults| defaults.thickness(app))
176            })
177            .unwrap_or(0.0);
178
179        // Prevent assertion since it is possible that context is null and no color
180        // is specified.
181        match effective_color {
182            None => BorderSide {
183                width: effective_width,
184                ..BorderSide::default()
185            },
186            Some(color) => BorderSide {
187                color,
188                width: effective_width,
189                ..BorderSide::default()
190            },
191        }
192    }
193}
194
195/// The defaults of the theme in `context`: Material 3's, or Material 2's when
196/// `ThemeData::use_material3` is false.
197fn divider_defaults(app: &mut App, context: BuildContext) -> Box<dyn DividerThemeDataGetters> {
198    if Theme::of(app, context).use_material3 {
199        Box::new(DividerDefaultsM3::new(context))
200    } else {
201        Box::new(DividerDefaultsM2::new(context))
202    }
203}
204
205impl StatelessWidget for Divider {
206    fn key(&self) -> Option<&KeyRef> {
207        self.key.as_ref()
208    }
209
210    fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef {
211        let divider_theme = DividerTheme::of(app, context);
212        let defaults = divider_defaults(app, context);
213        let height = self
214            .height
215            .or(divider_theme.space)
216            .or_else(|| defaults.space(app))
217            .expect("the defaults give a space");
218        let thickness = self
219            .thickness
220            .or(divider_theme.thickness)
221            .or_else(|| defaults.thickness(app))
222            .expect("the defaults give a thickness");
223        let indent = self
224            .indent
225            .or(divider_theme.indent)
226            .or_else(|| defaults.indent(app))
227            .expect("the defaults give an indent");
228        let end_indent = self
229            .end_indent
230            .or(divider_theme.end_indent)
231            .or_else(|| defaults.end_indent(app))
232            .expect("the defaults give an end indent");
233
234        SizedBox::new()
235            .height(height)
236            .child(
237                Center::new().child(
238                    Container::new()
239                        .height(thickness)
240                        .margin(EdgeInsetsGeometry::directional(
241                            indent, 0.0, end_indent, 0.0,
242                        ))
243                        .decoration(divider_decoration(
244                            self.radius
245                                .or(divider_theme.radius)
246                                .or_else(|| defaults.radius(app)),
247                            Border {
248                                bottom: Divider::create_border_side(
249                                    app,
250                                    Some(context),
251                                    self.color,
252                                    Some(thickness),
253                                ),
254                                ..Border::default()
255                            },
256                        )),
257                ),
258            )
259            .into_widget()
260    }
261}
262
263/// `BoxDecoration(borderRadius: radius, border: border)`.
264fn divider_decoration(radius: Option<BorderRadiusGeometry>, border: Border) -> BoxDecoration {
265    let decoration = BoxDecoration::new().border(border);
266    match radius {
267        Some(radius) => decoration.border_radius(radius),
268        None => decoration,
269    }
270}
271
272/// A thin vertical line, with padding on either side.
273///
274/// In the Material Design language, this represents a divider. Vertical
275/// dividers can be used in horizontally scrolling lists, such as a
276/// `ListView` with `ListView::scroll_direction` set to `Axis::Horizontal`.
277///
278/// The box's total width is controlled by [`width`](Self::width). The appropriate
279/// padding is automatically computed from the width.
280///
281/// See also:
282///
283///  * `ListView::separated`, which can be used to generate vertical dividers.
284///  * [`Divider`], which is the horizontal analog of this widget.
285///  * <https://material.io/design/components/dividers.html>
286#[derive(Debug, Default)]
287pub struct VerticalDivider {
288    pub key: Option<KeyRef>,
289
290    /// The divider's width.
291    ///
292    /// The divider itself is always drawn as a vertical line that is centered
293    /// within the width specified by this value.
294    ///
295    /// If this is null, then the [`DividerThemeData::space`] is used. If that is
296    /// also null, then this defaults to 16.0.
297    pub width: Option<f64>,
298
299    /// The thickness of the line drawn within the divider.
300    ///
301    /// A divider with a [`thickness`](Self::thickness) of 0.0 is always drawn as a line with a
302    /// width of exactly one device pixel.
303    ///
304    /// If this is null, then the [`DividerThemeData::thickness`] is used which
305    /// defaults to 0.0.
306    pub thickness: Option<f64>,
307
308    /// The amount of empty space on top of the divider.
309    ///
310    /// If this is null, then the [`DividerThemeData::indent`] is used. If that is
311    /// also null, then this defaults to 0.0.
312    pub indent: Option<f64>,
313
314    /// The amount of empty space under the divider.
315    ///
316    /// If this is null, then the [`DividerThemeData::end_indent`] is used. If that is
317    /// also null, then this defaults to 0.0.
318    pub end_indent: Option<f64>,
319
320    /// The color to use when painting the line.
321    ///
322    /// If this is null, then the [`DividerThemeData::color`] is used. If that is
323    /// also null, then this defaults to `ColorScheme::outline_variant`, or to
324    /// `ThemeData::divider_color` if `ThemeData::use_material3` is false.
325    pub color: Option<Color>,
326
327    /// The amount of radius for the border of the divider.
328    ///
329    /// If this is null, then the default radius of `BoxDecoration` will be used.
330    pub radius: Option<BorderRadiusGeometry>,
331}
332
333impl VerticalDivider {
334    /// Creates a Material Design vertical divider.
335    ///
336    /// The [`width`](Self::width), [`thickness`](Self::thickness), [`indent`](Self::indent),
337    /// and [`end_indent`](Self::end_indent) must be null or non-negative. Dart's optional named
338    /// arguments are the fluent setters.
339    pub fn new() -> VerticalDivider {
340        VerticalDivider::default()
341    }
342
343    /// Dart `VerticalDivider(key:)`.
344    pub fn key(mut self, key: KeyRef) -> VerticalDivider {
345        self.key = Some(key);
346        self
347    }
348
349    /// Dart `VerticalDivider(width:)`.
350    pub fn width(mut self, width: f64) -> VerticalDivider {
351        debug_assert!(width >= 0.0);
352        self.width = Some(width);
353        self
354    }
355
356    /// Dart `VerticalDivider(thickness:)`.
357    pub fn thickness(mut self, thickness: f64) -> VerticalDivider {
358        debug_assert!(thickness >= 0.0);
359        self.thickness = Some(thickness);
360        self
361    }
362
363    /// Dart `VerticalDivider(indent:)`.
364    pub fn indent(mut self, indent: f64) -> VerticalDivider {
365        debug_assert!(indent >= 0.0);
366        self.indent = Some(indent);
367        self
368    }
369
370    /// Dart `VerticalDivider(endIndent:)`.
371    pub fn end_indent(mut self, end_indent: f64) -> VerticalDivider {
372        debug_assert!(end_indent >= 0.0);
373        self.end_indent = Some(end_indent);
374        self
375    }
376
377    /// Dart `VerticalDivider(color:)`.
378    pub fn color(mut self, color: Color) -> VerticalDivider {
379        self.color = Some(color);
380        self
381    }
382
383    /// Dart `VerticalDivider(radius:)`.
384    pub fn radius(mut self, radius: impl Into<BorderRadiusGeometry>) -> VerticalDivider {
385        self.radius = Some(radius.into());
386        self
387    }
388}
389
390impl StatelessWidget for VerticalDivider {
391    fn key(&self) -> Option<&KeyRef> {
392        self.key.as_ref()
393    }
394
395    fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef {
396        let divider_theme = DividerTheme::of(app, context);
397        let defaults = divider_defaults(app, context);
398        let width = self
399            .width
400            .or(divider_theme.space)
401            .or_else(|| defaults.space(app))
402            .expect("the defaults give a space");
403        let thickness = self
404            .thickness
405            .or(divider_theme.thickness)
406            .or_else(|| defaults.thickness(app))
407            .expect("the defaults give a thickness");
408        let indent = self
409            .indent
410            .or(divider_theme.indent)
411            .or_else(|| defaults.indent(app))
412            .expect("the defaults give an indent");
413        let end_indent = self
414            .end_indent
415            .or(divider_theme.end_indent)
416            .or_else(|| defaults.end_indent(app))
417            .expect("the defaults give an end indent");
418
419        SizedBox::new()
420            .width(width)
421            .child(
422                Center::new().child(
423                    Container::new()
424                        .width(thickness)
425                        .margin(EdgeInsetsGeometry::directional(
426                            0.0, indent, 0.0, end_indent,
427                        ))
428                        .decoration(divider_decoration(
429                            self.radius
430                                .or(divider_theme.radius)
431                                .or_else(|| defaults.radius(app)),
432                            Border {
433                                left: Divider::create_border_side(
434                                    app,
435                                    Some(context),
436                                    self.color,
437                                    Some(thickness),
438                                ),
439                                ..Border::default()
440                            },
441                        )),
442                ),
443            )
444            .into_widget()
445    }
446}
447
448/// Dart's `_DividerDefaultsM2`.
449struct DividerDefaultsM2 {
450    /// Dart's `super(..)` arguments.
451    divider_theme_data: DividerThemeData,
452    context: BuildContext,
453}
454
455impl DividerDefaultsM2 {
456    fn new(context: BuildContext) -> DividerDefaultsM2 {
457        DividerDefaultsM2 {
458            divider_theme_data: DividerThemeData::new()
459                .space(16.0)
460                .thickness(0.0)
461                .indent(0.0)
462                .end_indent(0.0),
463            context,
464        }
465    }
466}
467
468impl DividerThemeDataGetters for DividerDefaultsM2 {
469    fn divider_theme_data(&self) -> &DividerThemeData {
470        &self.divider_theme_data
471    }
472
473    fn color(&self, app: &mut App) -> Option<Color> {
474        Some(Theme::of(app, self.context).divider_color)
475    }
476}
477
478#[cfg(test)]
479pub(crate) mod tests {
480    //! Ported from `test/divider_test.dart`.
481
482    use waft_embedder::{Radius, Rect, Size, TextDirection};
483    use waft_foundation::AppCell;
484    use waft_painting::BorderRadius;
485    use waft_widgets::{AnyElement, DecoratedBox, Directionality, Row, Text};
486
487    use waft_widgets::testing::{WidgetTester, find, test_widgets};
488
489    use super::*;
490    use crate::material::Material;
491    use crate::test_support::{PaintInspection, path_like};
492    use crate::theme_data::ThemeData;
493    use crate::tooltip::tests::{m2, m3, pump_app};
494
495    /// Dart's `tester.widget<Container>(find.byType(Container))`, which expects one `Container`.
496    pub(crate) fn only_container(tester: &WidgetTester) -> AnyElement {
497        let mut containers = find::by_type::<Container>().evaluate(tester);
498        assert_eq!(containers.len(), 1, "one Container");
499        containers.remove(0)
500    }
501
502    /// The `BoxDecoration` of [`only_container`].
503    pub(crate) fn decoration(tester: &WidgetTester) -> BoxDecoration {
504        let container = only_container(tester);
505        tester.widget(container, |container: &Container| {
506            container
507                .decoration
508                .as_ref()
509                .expect("the container has a decoration")
510                .as_any()
511                .downcast_ref::<BoxDecoration>()
512                .expect("a BoxDecoration")
513                .clone()
514        })
515    }
516
517    /// The `Border` of [`decoration`].
518    pub(crate) fn border(tester: &WidgetTester) -> Border {
519        *decoration(tester)
520            .border
521            .expect("the decoration has a border")
522            .as_any()
523            .downcast_ref::<Border>()
524            .expect("a Border")
525    }
526
527    /// Dart's `tester.getRect(find.byType(W))`.
528    pub(crate) fn rect_of<W: 'static>(tester: &WidgetTester) -> Rect {
529        let element = *find::by_type::<W>()
530            .evaluate(tester)
531            .first()
532            .expect("a widget of that type");
533        tester.get_rect(element)
534    }
535
536    /// The border radius of [`decoration`], which is a `BorderRadius`.
537    pub(crate) fn border_radius(tester: &WidgetTester) -> BorderRadius {
538        match decoration(tester).border_radius.expect("a border radius") {
539            BorderRadiusGeometry::BorderRadius(radius) => radius,
540            _ => panic!("a BorderRadius"),
541        }
542    }
543
544    pub(crate) fn assert_all_corners(radius: BorderRadius, expected: f64) {
545        assert_eq!(radius.bottom_left, Radius::circular(expected));
546        assert_eq!(radius.bottom_right, Radius::circular(expected));
547        assert_eq!(radius.top_left, Radius::circular(expected));
548        assert_eq!(radius.top_right, Radius::circular(expected));
549    }
550
551    fn ltr<K>(child: impl IntoWidget<K>) -> WidgetRef {
552        Directionality::new(TextDirection::Ltr, Center::new().child(child)).into_widget()
553    }
554
555    fn pump_centered(tester: &mut WidgetTester, theme: fn(&App) -> ThemeData, child: WidgetRef) {
556        pump_app(tester, theme, move |_app| {
557            Center::new().child(child).into_widget()
558        });
559    }
560
561    #[test]
562    fn material3_divider_control_test() {
563        test_widgets(|tester| {
564            pump_centered(tester, m3, Divider::new().into_widget());
565            assert_eq!(rect_of::<Divider>(tester).height(), 16.0);
566            assert_eq!(border(tester).bottom.width, 1.0);
567        });
568    }
569
570    #[test]
571    fn material2_divider_control_test() {
572        test_widgets(|tester| {
573            pump_centered(tester, m2, Divider::new().into_widget());
574            assert_eq!(rect_of::<Divider>(tester).height(), 16.0);
575            assert_eq!(border(tester).bottom.width, 0.0);
576        });
577    }
578
579    #[test]
580    fn divider_custom_thickness() {
581        test_widgets(|tester| {
582            tester.pump_widget(ltr(Divider::new().thickness(5.0)));
583            assert_eq!(border(tester).bottom.width, 5.0);
584        });
585    }
586
587    #[test]
588    fn divider_custom_radius() {
589        test_widgets(|tester| {
590            tester.pump_widget(ltr(Divider::new().radius(BorderRadius::circular(5.0))));
591            assert_all_corners(border_radius(tester), 5.0);
592        });
593    }
594
595    #[test]
596    fn horizontal_divider_custom_indentation() {
597        test_widgets(|tester| {
598            let custom_indent = 10.0;
599
600            tester.pump_widget(ltr(Divider::new().indent(custom_indent)));
601            // The divider line is drawn with a DecoratedBox with a border
602            let divider_rect = rect_of::<Divider>(tester);
603            let line_rect = rect_of::<DecoratedBox>(tester);
604            assert_eq!(line_rect.left, divider_rect.left + custom_indent);
605            assert_eq!(line_rect.right, divider_rect.right);
606
607            tester.pump_widget(ltr(Divider::new().end_indent(custom_indent)));
608            let divider_rect = rect_of::<Divider>(tester);
609            let line_rect = rect_of::<DecoratedBox>(tester);
610            assert_eq!(line_rect.left, divider_rect.left);
611            assert_eq!(line_rect.right, divider_rect.right - custom_indent);
612
613            tester.pump_widget(ltr(Divider::new()
614                .indent(custom_indent)
615                .end_indent(custom_indent)));
616            let divider_rect = rect_of::<Divider>(tester);
617            let line_rect = rect_of::<DecoratedBox>(tester);
618            assert_eq!(line_rect.left, divider_rect.left + custom_indent);
619            assert_eq!(line_rect.right, divider_rect.right - custom_indent);
620        });
621    }
622
623    #[test]
624    fn material3_vertical_divider_test() {
625        test_widgets(|tester| {
626            pump_centered(tester, m3, VerticalDivider::new().into_widget());
627            assert_eq!(rect_of::<VerticalDivider>(tester).width(), 16.0);
628            assert_eq!(border(tester).left.width, 1.0);
629        });
630    }
631
632    #[test]
633    fn material2_vertical_divider_test() {
634        test_widgets(|tester| {
635            pump_centered(tester, m2, VerticalDivider::new().into_widget());
636            assert_eq!(rect_of::<VerticalDivider>(tester).width(), 16.0);
637            assert_eq!(border(tester).left.width, 0.0);
638        });
639    }
640
641    #[test]
642    fn vertical_divider_custom_thickness() {
643        test_widgets(|tester| {
644            tester.pump_widget(ltr(VerticalDivider::new().thickness(5.0)));
645            assert_eq!(border(tester).left.width, 5.0);
646        });
647    }
648
649    #[test]
650    fn vertical_divider_test_2() {
651        test_widgets(|tester| {
652            pump_app(tester, m2, |_app| {
653                Material::new()
654                    .child(SizedBox::new().height(24.0).child(Row::new().children([
655                        Text::new("Hey.").into_widget(),
656                        VerticalDivider::new().into_widget(),
657                    ])))
658                    .into_widget()
659            });
660            let container_box = *find::by_type::<Container>()
661                .evaluate(tester)
662                .last()
663                .expect("a Container");
664            let container_size: Size = tester.get_size(container_box);
665
666            assert_eq!(rect_of::<VerticalDivider>(tester).width(), 16.0);
667            assert_eq!(container_size.height(), 600.0);
668            // Dart: `paints..path(strokeWidth: 0.0)`.
669            let divider = *find::by_type::<VerticalDivider>()
670                .evaluate(tester)
671                .first()
672                .expect("a VerticalDivider");
673            let drawn = tester.painted_calls(tester.render_object(divider));
674            assert!(
675                drawn.len() == 1 && path_like(&drawn[0]).is_some(),
676                "{drawn:?}"
677            );
678        });
679    }
680
681    #[test]
682    fn vertical_divider_custom_indentation() {
683        test_widgets(|tester| {
684            let custom_indent = 10.0;
685
686            tester.pump_widget(ltr(VerticalDivider::new().indent(custom_indent)));
687            // The divider line is drawn with a DecoratedBox with a border
688            let divider_rect = rect_of::<VerticalDivider>(tester);
689            let line_rect = rect_of::<DecoratedBox>(tester);
690            assert_eq!(line_rect.top, divider_rect.top + custom_indent);
691            assert_eq!(line_rect.bottom, divider_rect.bottom);
692
693            tester.pump_widget(ltr(VerticalDivider::new().end_indent(custom_indent)));
694            let divider_rect = rect_of::<VerticalDivider>(tester);
695            let line_rect = rect_of::<DecoratedBox>(tester);
696            assert_eq!(line_rect.top, divider_rect.top);
697            assert_eq!(line_rect.bottom, divider_rect.bottom - custom_indent);
698
699            tester.pump_widget(ltr(VerticalDivider::new()
700                .indent(custom_indent)
701                .end_indent(custom_indent)));
702            let divider_rect = rect_of::<VerticalDivider>(tester);
703            let line_rect = rect_of::<DecoratedBox>(tester);
704            assert_eq!(line_rect.top, divider_rect.top + custom_indent);
705            assert_eq!(line_rect.bottom, divider_rect.bottom - custom_indent);
706        });
707    }
708
709    #[test]
710    fn vertical_divider_custom_radius() {
711        test_widgets(|tester| {
712            tester.pump_widget(ltr(
713                VerticalDivider::new().radius(BorderRadius::circular(5.0))
714            ));
715            assert_all_corners(border_radius(tester), 5.0);
716        });
717    }
718
719    // Regression test for https://github.com/flutter/flutter/issues/39533
720    #[test]
721    fn create_border_side_does_not_throw_exception_with_null_context() {
722        let cell = AppCell::new();
723        let side = Divider::create_border_side(&mut cell.borrow_mut(), None, None, None);
724        assert_eq!(
725            side,
726            BorderSide {
727                width: 0.0,
728                ..BorderSide::default()
729            }
730        );
731    }
732
733    #[test]
734    fn divider_does_not_crash_at_zero_area() {
735        test_widgets(|tester| {
736            pump_app(tester, m3, |_app| {
737                Center::new()
738                    .child(SizedBox::shrink().child(Divider::new()))
739                    .into_widget()
740            });
741            assert_eq!(rect_of::<Divider>(tester).size(), Size::ZERO);
742        });
743    }
744
745    #[test]
746    fn vertical_divider_does_not_crash_at_zero_area() {
747        test_widgets(|tester| {
748            pump_app(tester, m3, |_app| {
749                Center::new()
750                    .child(SizedBox::shrink().child(VerticalDivider::new()))
751                    .into_widget()
752            });
753            assert_eq!(rect_of::<VerticalDivider>(tester).size(), Size::ZERO);
754        });
755    }
756}