custom_theme_card.dart 4.64 KB
import 'package:doublefeel_flutter/core/util/size_extensions.dart';
import 'package:flutter/material.dart';

import '../models/watch_theme_models.dart';
import 'watch_theme_character_avatar.dart';
import 'watch_theme_colors.dart';
import 'watch_theme_pro_badge.dart';
import 'watch_theme_section_card.dart';

class CustomThemeCard extends StatelessWidget {
  const CustomThemeCard({
    super.key,
    required this.isPremium,
    required this.hasCustomThemes,
    required this.customThemes,
    required this.onCreateTap,
    this.onThemeTap,
  });

  final bool isPremium;
  final bool hasCustomThemes;
  final List<WatchThemeItem> customThemes;
  final VoidCallback onCreateTap;
  final ValueChanged<WatchThemeItem>? onThemeTap;

  @override
  Widget build(BuildContext context) {
    return WatchThemeSectionCard(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          WatchThemeSectionTitle(
            '自定义主题',
            trailing: isPremium ? null : const WatchThemeProBadge(),
          ),
          SizedBox(height: 4.dp),
          Text(
            '用创意记录每一次情绪波动,打造懂你的专属表盘吧~',
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
            style: TextStyle(
              color: WatchThemeColors.textSecondary,
              fontSize: 12.dp,
              fontWeight: FontWeight.w400,
              height: 1.25,
            ),
          ),
          SizedBox(height: 14.dp),
          _CreateThemeButton(onTap: onCreateTap),
          if (hasCustomThemes) ...[
            SizedBox(height: 12.dp),
            Row(
              children: [
                for (var index = 0; index < customThemes.length; index++) ...[
                  _CustomThemeItem(
                    item: customThemes[index],
                    onTap: onThemeTap == null
                        ? null
                        : () => onThemeTap!(customThemes[index]),
                  ),
                  if (index != customThemes.length - 1) SizedBox(width: 20.dp),
                ],
              ],
            ),
          ],
        ],
      ),
    );
  }
}

class _CreateThemeButton extends StatelessWidget {
  const _CreateThemeButton({required this.onTap});

  final VoidCallback onTap;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: onTap,
      child: Container(
        height: 48.dp,
        padding: EdgeInsets.symmetric(horizontal: 20.dp),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(12.dp),
          gradient: const LinearGradient(
            begin: Alignment.centerLeft,
            end: Alignment.centerRight,
            colors: [
              Color(0xFFFFFFD0),
              Color(0xFFFFD1DB),
              Color(0xFFF0CDFF),
              Color(0xFFCFE8FF),
            ],
            stops: [0, 0.4, 0.7, 1],
          ),
        ),
        child: Row(
          children: [
            Icon(
              Icons.palette_outlined,
              color: WatchThemeColors.overload,
              size: 28.dp,
            ),
            SizedBox(width: 8.dp),
            Text(
              '创作主题',
              style: TextStyle(
                color: WatchThemeColors.textPrimary,
                fontSize: 14.dp,
                fontWeight: FontWeight.w500,
                height: 1.25,
              ),
            ),
            const Spacer(),
            Icon(
              Icons.chevron_right,
              color: WatchThemeColors.textSecondary,
              size: 20.dp,
            ),
          ],
        ),
      ),
    );
  }
}

class _CustomThemeItem extends StatelessWidget {
  const _CustomThemeItem({required this.item, this.onTap});

  final WatchThemeItem item;
  final VoidCallback? onTap;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: onTap,
      child: SizedBox(
        width: 88.dp,
        child: Column(
          children: [
            WatchThemeCharacterAvatar(
              size: 88,
              assetPath: item.infoList.firstOrNull?.assetPath,
              empty: item.infoList.firstOrNull?.assetPath == null,
            ),
            SizedBox(height: 8.dp),
            Text(
              item.title,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                color: WatchThemeColors.textPrimary,
                fontSize: 12.dp,
                fontWeight: FontWeight.w400,
                height: 1.25,
              ),
            ),
          ],
        ),
      ),
    );
  }
}