79 lines
2.5 KiB
Dart
79 lines
2.5 KiB
Dart
import 'package:app/config/theme/theme.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../config/config.dart';
|
|
|
|
class Button extends StatelessWidget {
|
|
final double? width;
|
|
final String text;
|
|
final ThemeType type;
|
|
final BorderRadius radius;
|
|
final VoidCallback onPressed;
|
|
final bool loading;
|
|
final bool disabled;
|
|
|
|
const Button({
|
|
super.key,
|
|
this.width,
|
|
this.radius = const BorderRadius.all(Radius.circular(80)),
|
|
required this.text,
|
|
required 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(
|
|
color: type != ThemeType.info ? Colors.white : Colors.black,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|