surface static method
FamilySurfaceBuilder
surface({
- Color? backgroundColor,
- EdgeInsets padding = EdgeInsets.zero,
- BorderRadius? borderRadius,
- BorderRadius? floatingBorderRadius,
- double elevation = 0,
- bool showDragHandle = false,
A Material surface.
Docked, it's the standard bottom sheet: it touches the bottom and sides
of the screen, rounds its top corners, and runs its colour behind the
home indicator while keeping the pages above it. Give it padding to
float it as a card instead, with every corner rounded.
Floating, it rounds every corner and drops the drag handle.
borderRadius and floatingBorderRadius replace those corners when set,
for the docked and the floating sheet.
Implementation
static FamilySurfaceBuilder surface({
Color? backgroundColor,
EdgeInsets padding = EdgeInsets.zero,
BorderRadius? borderRadius,
BorderRadius? floatingBorderRadius,
double elevation = 0,
bool showDragHandle = false,
}) {
return (context, child) {
final isDocked =
FamilyPresentation.maybeOf(context) != FamilyPresentation.floating;
final isFlush = isDocked && padding == EdgeInsets.zero;
final colors = Theme.of(context).colorScheme;
// Flush against the bottom edge, the pages keep clear of the home
// indicator inside the surface, so its colour runs behind it.
final bottomInset = isFlush ? MediaQuery.paddingOf(context).bottom : 0.0;
// Flush, only the top corners round
final defaultCorners = isFlush
? const BorderRadius.vertical(top: _defaultRadius)
: const BorderRadius.all(_defaultRadius);
final corners = isDocked
? borderRadius ?? defaultCorners
: floatingBorderRadius ?? defaultCorners;
final surface = Material(
color: backgroundColor ?? colors.surfaceContainerLow,
elevation: elevation,
borderRadius: corners,
clipBehavior: Clip.antiAlias,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (showDragHandle && isDocked)
_DragHandle(color: colors.onSurfaceVariant),
Flexible(
child: Padding(
padding: EdgeInsets.only(bottom: bottomInset),
child: child,
),
),
],
),
);
if (!isDocked || isFlush) return surface;
return SafeArea(
top: false,
child: Padding(padding: padding, child: surface),
);
};
}