Files
jinzhi/lib/common/widgets/app_state_card.dart
T
2026-06-18 15:02:28 +08:00

113 lines
3.7 KiB
Dart

import 'package:flutter/material.dart';
import '../theme/app_text.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
enum AppStateButtonStyle { filled, outline }
class AppStateCard extends StatelessWidget {
const AppStateCard({
super.key,
required this.icon,
required this.title,
required this.subtitle,
this.buttonLabel,
this.onButtonPressed,
this.buttonStyle = AppStateButtonStyle.outline,
});
final IconData icon;
final String title;
final String subtitle;
final String? buttonLabel;
final VoidCallback? onButtonPressed;
final AppStateButtonStyle buttonStyle;
@override
Widget build(BuildContext context) {
final cs = ShadTheme.of(context).colorScheme;
final hasAction = buttonLabel != null && onButtonPressed != null;
return ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 320),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: 104,
height: 104,
alignment: Alignment.center,
decoration: BoxDecoration(
color: cs.secondary,
shape: BoxShape.circle,
),
child: Icon(icon, size: 46, color: cs.mutedForeground),
),
const SizedBox(height: 22),
Text(
title,
textAlign: TextAlign.center,
style: AppText.cardTitle.copyWith(
fontSize: 22,
fontWeight: FontWeight.w700,
color: cs.foreground,
height: 1.2,
),
),
const SizedBox(height: 10),
Text(
subtitle,
textAlign: TextAlign.center,
style: AppText.body.copyWith(
fontSize: 15,
color: cs.mutedForeground,
height: 1.5,
),
),
if (hasAction) ...[
const SizedBox(height: 20),
SizedBox(
height: 42,
child: buttonStyle == AppStateButtonStyle.filled
? FilledButton(
onPressed: onButtonPressed,
style: FilledButton.styleFrom(
backgroundColor: cs.foreground,
foregroundColor: cs.background,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
padding: const EdgeInsets.symmetric(horizontal: 18),
textStyle: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
),
),
child: Text(buttonLabel!),
)
: OutlinedButton(
onPressed: onButtonPressed,
style: OutlinedButton.styleFrom(
foregroundColor: cs.foreground,
side: BorderSide(color: cs.border),
backgroundColor: cs.background,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
padding: const EdgeInsets.symmetric(horizontal: 18),
textStyle: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
),
),
child: Text(buttonLabel!),
),
),
],
],
),
);
}
}