createBorderSide method Null safety
- BuildContext? context,
- {Color? color,
- double? width}
Computes the BorderSide that represents a divider.
If color
is null, then DividerThemeData.color is used. If that is also
null, then ThemeData.dividerColor is used.
If width
is null, then DividerThemeData.thickness is used. If that is
also null, then this defaults to 0.0 (a hairline border).
If context
is null, the default color of BorderSide is used and the
default width of 0.0 is used.
This example uses this method to create a box that has a divider above and
below it. This is sometimes useful with lists, for instance, to separate a
scrollable section from the rest of the interface.
DecoratedBox(
decoration: BoxDecoration(
border: Border(
top: Divider.createBorderSide(context),
bottom: Divider.createBorderSide(context),
),
),
// child: ...
)
Implementation
static BorderSide createBorderSide(BuildContext? context, { Color? color, double? width }) {
final Color? effectiveColor = color
?? (context != null ? (DividerTheme.of(context).color ?? Theme.of(context).dividerColor) : null);
final double effectiveWidth = width
?? (context != null ? DividerTheme.of(context).thickness : null)
?? 0.0;
// Prevent assertion since it is possible that context is null and no color
// is specified.
if (effectiveColor == null) {
return BorderSide(
width: effectiveWidth,
);
}
return BorderSide(
color: effectiveColor,
width: effectiveWidth,
);
}