Files
social-app/apps/lib/shared/widgets/app_button.dart
T

137 lines
4.4 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import '../../core/theme/design_tokens.dart';
import 'app_loading_indicator.dart';
class AppButton extends StatelessWidget {
const AppButton({
super.key,
required this.text,
this.onPressed,
this.isOutlined = false,
this.height = 52,
this.isLoading = false,
});
final String text;
final VoidCallback? onPressed;
final bool isOutlined;
final double height;
final bool isLoading;
@override
Widget build(BuildContext context) {
final isDisabled = onPressed == null || isLoading;
if (isOutlined) {
return SizedBox(
height: height,
child: OutlinedButton(
onPressed: isLoading ? null : onPressed,
style: OutlinedButton.styleFrom(
backgroundColor: isDisabled
? AppColors.authSecondaryButtonBackground.withValues(
alpha: 0.55,
)
: AppColors.authSecondaryButtonBackground,
foregroundColor: isDisabled
? AppColors.authLinkMuted
: AppColors.authSecondaryButtonText,
side: BorderSide(
color: isDisabled
? AppColors.authSecondaryButtonBorder.withValues(alpha: 0.7)
: AppColors.authSecondaryButtonBorder,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppRadius.full),
),
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xl),
),
child: isLoading
? const AppLoadingIndicator(
variant: AppLoadingVariant.button,
color: AppColors.authSecondaryButtonText,
trackColor: AppColors.authSecondaryButtonBorder,
)
: Text(
text,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w700,
letterSpacing: 0.2,
),
),
),
);
}
return DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(AppRadius.full),
boxShadow: isDisabled
? const []
: [
BoxShadow(
color: AppColors.blue300.withValues(alpha: 0.24),
blurRadius: 18,
offset: const Offset(0, 10),
),
],
),
child: SizedBox(
height: height,
width: double.infinity,
child: ElevatedButton(
onPressed: isLoading ? null : onPressed,
style: ButtonStyle(
elevation: const WidgetStatePropertyAll(0),
backgroundColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.disabled)) {
return AppColors.authPrimaryButtonDisabled;
}
if (states.contains(WidgetState.pressed)) {
return AppColors.authPrimaryButtonPressed;
}
return AppColors.authPrimaryButton;
}),
foregroundColor: const WidgetStatePropertyAll(
AppColors.authPrimaryButtonText,
),
overlayColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.pressed)) {
return AppColors.white.withValues(alpha: 0.08);
}
return null;
}),
shape: WidgetStatePropertyAll(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppRadius.full),
),
),
padding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(horizontal: AppSpacing.xl),
),
),
child: isLoading
? const AppLoadingIndicator(
variant: AppLoadingVariant.button,
color: AppColors.authPrimaryButtonText,
trackColor: AppColors.blue400,
)
: Text(
text,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w700,
letterSpacing: 0.2,
color: isDisabled
? AppColors.authLinkMuted
: AppColors.authPrimaryButtonText,
),
),
),
),
);
}
}