import 'package:app/global/theme/theme.dart'; import 'package:flutter/material.dart'; import '../config/config.dart'; class Button extends StatelessWidget { final double? width; final String text; final TextStyle textStyle; final ThemeType type; final BorderRadius radius; final VoidCallback? onPressed; final bool loading; final bool disabled; final Widget? icon; const Button({ super.key, this.icon, this.width, this.textStyle = const TextStyle(), this.radius = const BorderRadius.all(Radius.circular(80)), required this.text, this.onPressed, this.type = ThemeType.primary, this.loading = false, this.disabled = false, }); @override Widget build(BuildContext context) { final bgDecoration = switch (type) { ThemeType.primary => BoxDecoration(color: Theme.of(context).primaryColor), ThemeType.success => BoxDecoration(color: context.success), ThemeType.danger => BoxDecoration(color: context.danger), ThemeType.warning => BoxDecoration(color: context.warning), ThemeType.info => BoxDecoration(color: context.info), }; return Opacity( opacity: disabled || loading ? 0.5 : 1, child: Container( width: width, decoration: bgDecoration.copyWith(borderRadius: radius), child: Material( type: MaterialType.transparency, // 让波纹依附在上层容器 child: InkWell( borderRadius: radius, onTap: disabled || loading ? null : onPressed, splashColor: Colors.white.withValues(alpha: 0.2), highlightColor: Colors.white.withValues(alpha: 0.2), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 7), child: Row( spacing: 10, mainAxisAlignment: MainAxisAlignment.center, children: [ if (loading) const SizedBox( width: 15, height: 15, child: CircularProgressIndicator( strokeWidth: 2, valueColor: AlwaysStoppedAnimation(Colors.white), ), ), Text( text, style: textStyle.copyWith( color: type != ThemeType.info ? Colors.white : Colors.black, ), textAlign: TextAlign.center, ), ], ), ), ), ), ), ); } }