Files
max_print_plus/lib/widget/my_button.dart
2024-09-27 22:09:30 +07:00

74 lines
2.4 KiB
Dart

import 'package:flutter/material.dart';
class MyButton extends StatelessWidget {
final String text;
final Function()? press;
final Color? color;
final Color? textColor;
final Color? borderColor;
final double? width;
final double? heigth;
final double? borderRadius;
final double? textSize;
final EdgeInsetsGeometry? padding;
const MyButton(
{Key? key,
required this.text,
required this.press,
this.color,
this.padding,
this.textColor,
this.width,
this.heigth,
this.borderRadius,
this.borderColor,
this.textSize})
: super(key: key);
@override
Widget build(BuildContext context) {
return SizedBox(
height: heigth,
width: width,
child: ElevatedButton(
onPressed: press,
style: ButtonStyle(
elevation: WidgetStateProperty.all(0),
padding: WidgetStateProperty.all(
padding ?? const EdgeInsets.all(16.0)),
backgroundColor: WidgetStateProperty.resolveWith<Color>(
(Set<WidgetState> states) {
if (states.contains(WidgetState.pressed)) {
return const Color(0xFFDCDEE0);
} else if (states.contains(WidgetState.disabled)) {
return const Color(0xFFF2F2F5);
} else if (states.contains(WidgetState.focused)) {
return const Color(0xFFFFC700);
}
return color ??
const Color(0xFFFFC700); // Use the component's default.
},
),
textStyle: WidgetStateProperty.all<TextStyle>(
TextStyle(color: textColor ?? const Color(0xFF242632))),
shape: WidgetStateProperty.resolveWith<RoundedRectangleBorder>(
(states) {
return RoundedRectangleBorder(
side: !(states.contains(WidgetState.pressed))
? BorderSide(color: borderColor ?? Colors.transparent)
: const BorderSide(color: Colors.transparent),
borderRadius:
BorderRadius.circular(borderRadius ?? 1000.0));
})),
child: Text(
text,
style: TextStyle(
color: textColor ?? Colors.white,
fontSize: textSize,
fontWeight: FontWeight.w600),
)),
);
}
}