import 'dart:ui'; import 'package:flutter/material.dart'; class FikoYTCard extends StatelessWidget { const FikoYTCard({super.key, this.children = const [], this.theme}); final List children; final FikoYTCardTheme? theme; @override Widget build(BuildContext context) { final cardTheme = theme ?? Theme.of(context).extension() ?? FikoYTCardTheme(); return Container( margin: cardTheme.margin ?? const EdgeInsets.all(5.0), padding: cardTheme.padding ?? const EdgeInsets.all(5.0), alignment: Alignment.topLeft, constraints: cardTheme.boxConstraints, decoration: BoxDecoration( color: cardTheme.backgroundColor ?? Colors.white, border: cardTheme.border, borderRadius: cardTheme.borderRadius ?? BorderRadius.all(Radius.circular(cardTheme.radius ?? 5.0)), boxShadow: [ BoxShadow( color: cardTheme.shadowColor ?? Colors.black26, offset: const Offset(0, 0), spreadRadius: -1, blurRadius: cardTheme.elevation ?? 5.0, blurStyle: BlurStyle.outer, ), ], ), child: Column( crossAxisAlignment: cardTheme.crossAxisAlignment ?? CrossAxisAlignment.start, mainAxisAlignment: cardTheme.mainAxisAlignment ?? MainAxisAlignment.start, children: [ ...List.generate( children.length, (index) => Padding( padding: EdgeInsets.only(bottom: index < children.length - 1 ? (cardTheme.spacing ?? 3.0) : 0.0), child: children[index], )) ]), ); } } class FikoYTCardTheme extends ThemeExtension { FikoYTCardTheme({ this.backgroundColor, this.borderColor, this.border, this.shadowColor, this.radius, this.spacing, this.elevation, this.boxConstraints, this.borderRadius, this.padding, this.margin, this.boxShadow, this.mainAxisAlignment, this.crossAxisAlignment, }); final Color? backgroundColor; final Color? borderColor; final Border? border; final Color? shadowColor; final double? radius; final double? spacing; final double? elevation; final BoxConstraints? boxConstraints; final BorderRadiusGeometry? borderRadius; final EdgeInsetsGeometry? padding; final EdgeInsetsGeometry? margin; final List? boxShadow; final MainAxisAlignment? mainAxisAlignment; final CrossAxisAlignment? crossAxisAlignment; @override FikoYTCardTheme copyWith({ Color? backgroundColor, Color? borderColor, Border? border, Color? shadowColor, double? radius, double? spacing, double? elevation, BoxConstraints? boxConstraints, BorderRadiusGeometry? borderRadius, EdgeInsetsGeometry? padding, EdgeInsetsGeometry? margin, List? boxShadow, MainAxisAlignment? mainAxisAlignment, CrossAxisAlignment? crossAxisAlignment, }) { return FikoYTCardTheme( backgroundColor: backgroundColor ?? this.backgroundColor, borderRadius: borderRadius ?? this.borderRadius, border: border ?? this.border, padding: padding ?? this.padding, margin: margin ?? this.margin, radius: radius ?? this.radius, spacing: spacing ?? this.spacing, elevation: elevation ?? this.elevation, boxConstraints: boxConstraints ?? this.boxConstraints, borderColor: borderColor ?? this.borderColor, shadowColor: shadowColor ?? this.shadowColor, boxShadow: boxShadow ?? this.boxShadow, mainAxisAlignment: mainAxisAlignment ?? this.mainAxisAlignment, crossAxisAlignment: crossAxisAlignment ?? this.crossAxisAlignment, ); } @override FikoYTCardTheme lerp(ThemeExtension? other, double t) { if (other is! FikoYTCardTheme) { return this; } return FikoYTCardTheme( backgroundColor: Color.lerp(backgroundColor, other.backgroundColor, t), borderRadius: BorderRadius.lerp(borderRadius?.resolve(TextDirection.ltr), other.borderRadius?.resolve(TextDirection.ltr), t), border: Border.lerp(border, other.border, t), padding: EdgeInsets.lerp(padding?.resolve(TextDirection.ltr), other.padding?.resolve(TextDirection.ltr), t), margin: EdgeInsets.lerp(margin?.resolve(TextDirection.ltr), other.margin?.resolve(TextDirection.ltr), t), radius: lerpDouble(radius, other.radius, t), spacing: lerpDouble(spacing, other.spacing, t), elevation: lerpDouble(elevation, other.elevation, t), boxConstraints: BoxConstraints.lerp(boxConstraints, other.boxConstraints, t), borderColor: Color.lerp(borderColor, other.borderColor, t), shadowColor: Color.lerp(shadowColor, other.shadowColor, t), boxShadow: boxShadow ?? other.boxShadow, mainAxisAlignment: mainAxisAlignment ?? other.mainAxisAlignment, crossAxisAlignment: crossAxisAlignment ?? other.crossAxisAlignment, ); } }