Files
food_health_flutter/lib/widgets/ui_kit/button/custom_button.dart
2025-08-28 16:27:56 +08:00

85 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
///自定义按钮
///包括loading功能
class CustomButton extends StatelessWidget {
final Widget child;
final VoidCallback? onPressed;
final bool loading;
final bool round;
final bool disabled;
const CustomButton({
super.key,
required this.child,
this.onPressed,
this.loading = false,
this.round = true,
this.disabled = false,
});
@override
Widget build(BuildContext context) {
///自定义颜色
// switch (size) {
// case ButtonSize.small:
// height = 28;
// loadingSize = 16;
// fontSize = 12;
// padding = const EdgeInsets.symmetric(horizontal: 12);
// break;
// case ButtonSize.large:
// height = 48;
// loadingSize = 24;
// fontSize = 18;
// padding = const EdgeInsets.symmetric(horizontal: 20);
// break;
// case ButtonSize.medium:
// height = 45;
// loadingSize = 15;
// fontSize = 16;
// padding = const EdgeInsets.symmetric(horizontal: 16);
// break;
// }
void handClick() {
if (!loading && !disabled) {
onPressed?.call();
}
}
return Opacity(
opacity: disabled ? 0.5 : 1,
child: ElevatedButton(
onPressed: handClick,
style: ElevatedButton.styleFrom(
shape: round
? const StadiumBorder()
: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Visibility(
visible: loading,
child: Container(
margin: EdgeInsets.only(right: 8),
child: SizedBox.square(
dimension: 15,
child: CircularProgressIndicator(
color: Colors.white,
strokeWidth: 2,
),
),
),
),
child,
],
),
),
);
}
}