build method

  1. @override
Widget build(
  1. BuildContext context,
  2. Card content
)
override

Builds the layout widget tree for the given content item.

This method is called by the content system to render the content item with the specified layout.

Implementation

@override
Widget build(BuildContext context, Card content) {
  final theme = Theme.of(context);
  final innerChild = Text(content.title ?? 'Untitled');
  final onPressedAction = content.action != null
      ? () => content.action!.execute(context)
      : null;

  final button = switch (buttonType) {
    ButtonType.filled => ElevatedButton(
      style: ElevatedButton.styleFrom(
        backgroundColor: theme.colorScheme.primary,
        foregroundColor: theme.colorScheme.onPrimary,
      ),
      onPressed: onPressedAction,
      child: innerChild,
    ),
    ButtonType.outlined => OutlinedButton(
      onPressed: onPressedAction,
      child: innerChild,
    ),
    ButtonType.text => TextButton(
      onPressed: onPressedAction,
      child: innerChild,
    ),
  };

  return Padding(
    padding: const EdgeInsets.symmetric(horizontal: 8.0),
    child: isStretched
        ? SizedBox(width: double.maxFinite, child: button)
        : button,
  );
}