import 'package:flutter/material.dart'; import '../utils/enums/ui_theme.dart'; import '../utils/enums/ui_variant.dart'; import '../utils/theme/ui_color.dart'; class AppButton extends StatelessWidget { final Widget child; final VoidCallback? onPressed; final UiThemeType type; final UiVariant variant; final bool loading; final bool round; final bool disabled; const AppButton({ super.key, required this.child, this.onPressed, this.type = UiThemeType.primary, this.variant = UiVariant.solid, this.loading = false, this.round = true, this.disabled = false, }); @override Widget build(BuildContext context) { //设置颜色 final scheme = UiColor.getColorScheme( context, type: type, variant: variant, ); return Opacity( opacity: disabled ? 0.5 : 1, child: ElevatedButton( onPressed: () { if (!loading && !disabled) { onPressed?.call(); } }, style: ElevatedButton.styleFrom( backgroundColor: scheme.background, // 应用自定义颜色 shadowColor: Colors.transparent, foregroundColor: scheme.foreground, shape: round ? const StadiumBorder() : RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), ), child: Row( mainAxisAlignment: MainAxisAlignment.center, spacing: 8, children: [ Visibility( visible: loading, child: SizedBox.square( dimension: 15, child: CircularProgressIndicator( color: scheme.foreground, strokeWidth: 2, ), ), ), child, ], ), ), ); } }