rtc_prd/airhub_app/lib/widgets/gradient_button.dart
2026-02-06 16:03:32 +08:00

152 lines
4.6 KiB
Dart

import 'package:flutter/material.dart';
import '../theme/app_colors.dart';
class GradientButton extends StatelessWidget {
final String text;
final VoidCallback? onPressed;
final double width;
final double height;
final bool isLoading;
final Gradient? gradient;
const GradientButton({
super.key,
required this.text,
this.onPressed,
this.width = double.infinity,
this.height = 50.0, // Changed from 56 to 50 to match CSS
this.isLoading = false,
this.gradient,
});
// Check if using plush/capybara gradient
bool get _isPlushGradient {
if (gradient == null) return false;
if (gradient is LinearGradient) {
final lg = gradient as LinearGradient;
// Check if colors match plush gradient colors
if (lg.colors.length >= 2) {
return lg.colors.first.value == 0xFFECCFA8 ||
lg.colors.last.value == 0xFFC99672;
}
}
return false;
}
List<BoxShadow> get _boxShadows {
if (_isPlushGradient) {
// Warm brown glow for Capybara plush gradient
return [
BoxShadow(
color: const Color(0xFFC99672).withOpacity(0.35),
offset: Offset.zero,
blurRadius: 15,
),
BoxShadow(
color: const Color(0xFFC99672).withOpacity(0.25),
offset: Offset.zero,
blurRadius: 30,
),
BoxShadow(
color: const Color(0xFFC99672).withOpacity(0.4),
offset: const Offset(0, 6),
blurRadius: 20,
),
];
} else {
// Purple/indigo glow for primary gradient
return [
BoxShadow(
color: const Color(0xFF6366F1).withOpacity(0.4),
offset: const Offset(0, 4),
blurRadius: 20,
),
BoxShadow(
color: const Color(0xFF8B5CF6).withOpacity(0.2),
offset: Offset.zero,
blurRadius: 40,
),
];
}
}
@override
Widget build(BuildContext context) {
final bool isDisabled = onPressed == null || isLoading;
return Opacity(
opacity: isDisabled ? 0.7 : 1.0,
child: Container(
width: width,
height: height,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(height / 2),
gradient: gradient ?? AppColors.btnPrimaryGradient,
boxShadow: _boxShadows,
),
child: Stack(
children: [
// Shine overlay (top half gradient)
Positioned.fill(
child: ClipRRect(
borderRadius: BorderRadius.circular(height / 2),
child: DecoratedBox(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.white.withOpacity(0.15),
Colors.transparent,
],
stops: const [0.0, 0.5],
),
),
),
),
),
// Button content
Material(
color: Colors.transparent,
child: InkWell(
onTap: isDisabled ? null : onPressed,
borderRadius: BorderRadius.circular(height / 2),
splashColor: Colors.white.withOpacity(0.2),
highlightColor: Colors.white.withOpacity(0.1),
child: Center(
child: isLoading
? const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
color: Colors.white,
strokeWidth: 2.5,
),
)
: Text(
text,
style: TextStyle(
fontFamily: 'Inter',
fontSize: _isPlushGradient ? 18 : 17,
fontWeight:
_isPlushGradient ? FontWeight.w700 : FontWeight.w600,
color: Colors.white,
shadows: const [
Shadow(
offset: Offset(0, 1),
blurRadius: 2,
color: Colors.black12,
),
],
),
),
),
),
),
],
),
),
);
}
}