120 lines
3.7 KiB
Dart
120 lines
3.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
import '../../core/theme/colors.dart';
|
|
import '../../core/utils/size_config.dart';
|
|
import '../login/strings/login_strings.dart';
|
|
|
|
class BaseButton extends StatelessWidget {
|
|
final bool isEnabled;
|
|
final VoidCallback? onPressed;
|
|
final String? text;
|
|
final Color? textColor;
|
|
final Color? backgroundColor;
|
|
final Color? borderColor;
|
|
final double? borderWidth;
|
|
final double? borderRadius;
|
|
final double? elevation;
|
|
final double? width;
|
|
final double? height;
|
|
final bool isLoading;
|
|
final String? icon;
|
|
final Color? iconColor;
|
|
final double? fontSize;
|
|
|
|
const BaseButton({
|
|
required this.isEnabled,
|
|
required this.onPressed,
|
|
this.text,
|
|
this.textColor,
|
|
this.backgroundColor,
|
|
this.borderColor,
|
|
this.borderWidth,
|
|
this.borderRadius,
|
|
this.elevation,
|
|
this.width,
|
|
this.height,
|
|
this.isLoading = false,
|
|
this.icon,
|
|
this.iconColor,
|
|
this.fontSize,
|
|
super.key,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return isLoading
|
|
? Container(
|
|
width: double.infinity,
|
|
height: height ?? 55.0.h(),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.mainBlue,
|
|
borderRadius: BorderRadius.circular(28.0.w()),
|
|
),
|
|
child: Center(
|
|
child: SizedBox(
|
|
width: 30.0.w(),
|
|
height: 30.0.w(),
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 4.0,
|
|
color: AppColors.white,
|
|
),
|
|
),
|
|
),
|
|
)
|
|
: SizedBox(
|
|
width: width ?? double.infinity,
|
|
height: height ?? 55.0.h(),
|
|
child: ElevatedButton(
|
|
onPressed: isEnabled ? onPressed : null,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor:
|
|
backgroundColor ??
|
|
(isEnabled ? AppColors.mainBlue : AppColors.backgroundColor),
|
|
foregroundColor: textColor ?? AppColors.backgroundColor,
|
|
elevation: elevation ?? 0,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(borderRadius ?? 28.0.w()),
|
|
side: BorderSide(
|
|
color: borderColor ?? Colors.transparent,
|
|
width: borderWidth ?? 0,
|
|
),
|
|
),
|
|
),
|
|
child:
|
|
icon != null
|
|
? Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
SvgPicture.asset(
|
|
icon!,
|
|
colorFilter: ColorFilter.mode(
|
|
iconColor ?? AppColors.white,
|
|
BlendMode.srcIn,
|
|
),
|
|
),
|
|
SizedBox(width: 7.0.w()),
|
|
Text(
|
|
text ?? LoginStrings.loginButton,
|
|
style: TextStyle(
|
|
fontSize: fontSize ?? 16.0.sp(),
|
|
fontWeight: FontWeight.bold,
|
|
color: textColor ?? AppColors.white,
|
|
),
|
|
),
|
|
],
|
|
)
|
|
: Text(
|
|
text ?? LoginStrings.loginButton,
|
|
style: TextStyle(
|
|
fontSize: fontSize ?? 16.0.sp(),
|
|
fontWeight: FontWeight.bold,
|
|
color: textColor ?? AppColors.white,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|