82 lines
2.1 KiB
Dart
82 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class PrimaryButton extends StatelessWidget {
|
|
final VoidCallback? onPressed;
|
|
final String text;
|
|
final Color color;
|
|
final double height;
|
|
final double? width;
|
|
final double size;
|
|
final double radius;
|
|
final double padding;
|
|
final Widget? leading;
|
|
final double leadingGap;
|
|
|
|
const PrimaryButton({
|
|
super.key,
|
|
required this.text,
|
|
required this.color,
|
|
this.onPressed,
|
|
this.height = 60,
|
|
this.width,
|
|
this.size = 18,
|
|
this.radius = 18,
|
|
this.padding = 0,
|
|
this.leading,
|
|
this.leadingGap = 10,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final bgResolver = WidgetStateProperty.resolveWith<Color>((states) {
|
|
if (states.contains(WidgetState.disabled)) {
|
|
return color.withValues(alpha: 0.5);
|
|
}
|
|
return color;
|
|
});
|
|
|
|
return FilledButton(
|
|
style: ButtonStyle(
|
|
backgroundColor: bgResolver,
|
|
padding: WidgetStatePropertyAll<EdgeInsetsGeometry>(
|
|
EdgeInsets.symmetric(horizontal: padding),
|
|
),
|
|
shape: WidgetStatePropertyAll<OutlinedBorder>(
|
|
RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(radius)),
|
|
),
|
|
),
|
|
),
|
|
onPressed: onPressed,
|
|
child: SizedBox(
|
|
width: width,
|
|
height: height,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
// mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (leading != null) ...[
|
|
IconTheme.merge(
|
|
data: const IconThemeData(color: Colors.white, size: 20),
|
|
child: leading!,
|
|
),
|
|
SizedBox(width: leadingGap),
|
|
],
|
|
Text(
|
|
text,
|
|
overflow: TextOverflow.ellipsis,
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
fontSize: size,
|
|
fontWeight: FontWeight.w500,
|
|
letterSpacing: 0,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|