mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 14:47:23 +00:00
110 lines
3.5 KiB
Dart
110 lines
3.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:syncrow_web/utils/color_manager.dart';
|
|
|
|
class DefaultButton extends StatelessWidget {
|
|
const DefaultButton({
|
|
super.key,
|
|
this.enabled = true,
|
|
this.onPressed,
|
|
required this.child,
|
|
this.isSecondary = false,
|
|
this.isLoading = false,
|
|
this.isDone = false,
|
|
this.customTextStyle,
|
|
this.customButtonStyle,
|
|
this.backgroundColor,
|
|
this.foregroundColor,
|
|
this.borderRadius,
|
|
this.height = 40,
|
|
this.padding,
|
|
this.borderColor,
|
|
this.elevation,
|
|
this.borderWidth = 1.0,
|
|
});
|
|
final void Function()? onPressed;
|
|
final Widget child;
|
|
final double? height;
|
|
final bool isSecondary;
|
|
final double? borderRadius;
|
|
final double borderWidth;
|
|
final bool enabled;
|
|
final double? padding;
|
|
final bool isDone;
|
|
final bool isLoading;
|
|
final TextStyle? customTextStyle;
|
|
final ButtonStyle? customButtonStyle;
|
|
final Color? backgroundColor;
|
|
final Color? foregroundColor;
|
|
final Color? borderColor;
|
|
final double? elevation;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ElevatedButton(
|
|
onPressed: enabled ? onPressed : null,
|
|
style: isSecondary
|
|
? null
|
|
: customButtonStyle ??
|
|
ButtonStyle(
|
|
textStyle: WidgetStateProperty.all(
|
|
customTextStyle ??
|
|
Theme.of(context).textTheme.bodySmall!.copyWith(
|
|
fontSize: 13,
|
|
color: foregroundColor,
|
|
fontWeight: FontWeight.normal),
|
|
),
|
|
foregroundColor: WidgetStateProperty.all(
|
|
isSecondary
|
|
? Colors.black
|
|
: enabled
|
|
? foregroundColor ?? Colors.white
|
|
: Colors.black,
|
|
),
|
|
backgroundColor: WidgetStateProperty.resolveWith<Color>(
|
|
(Set<WidgetState> states) {
|
|
return enabled
|
|
? backgroundColor ?? ColorsManager.primaryColor
|
|
: Colors.black.withValues(alpha: 0.2);
|
|
}),
|
|
shape: WidgetStateProperty.all(
|
|
RoundedRectangleBorder(
|
|
side: BorderSide(
|
|
color: borderColor ?? Colors.transparent,
|
|
width: borderWidth,
|
|
),
|
|
borderRadius: BorderRadius.circular(borderRadius ?? 20),
|
|
),
|
|
),
|
|
fixedSize: height != null
|
|
? WidgetStateProperty.all(Size.fromHeight(height!))
|
|
: null,
|
|
padding: WidgetStateProperty.all(
|
|
EdgeInsets.all(padding ?? 10),
|
|
),
|
|
minimumSize: WidgetStateProperty.all(
|
|
const Size.fromHeight(10),
|
|
),
|
|
elevation: WidgetStateProperty.all(elevation ?? 0),
|
|
),
|
|
child: SizedBox(
|
|
height: height ?? 50,
|
|
child: Center(
|
|
child: isLoading
|
|
? const SizedBox.square(
|
|
dimension: 24,
|
|
child: CircularProgressIndicator(
|
|
color: Colors.white,
|
|
),
|
|
)
|
|
: isDone
|
|
? const Icon(
|
|
Icons.check_circle_outline,
|
|
color: Colors.white,
|
|
)
|
|
: child,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|