84 lines
2.5 KiB
Dart
84 lines
2.5 KiB
Dart
import 'package:didvan/config/design_config.dart';
|
|
import 'package:didvan/config/theme_data.dart';
|
|
import 'package:didvan/models/enums.dart';
|
|
import 'package:didvan/views/widgets/didvan/text.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class DidvanButton extends StatelessWidget {
|
|
final VoidCallback? onPressed;
|
|
final String? title;
|
|
final double? width;
|
|
final ButtonStyleMode style;
|
|
final bool enabled;
|
|
final double? height;
|
|
const DidvanButton({
|
|
Key? key,
|
|
this.onPressed,
|
|
this.title,
|
|
this.style = ButtonStyleMode.primary,
|
|
this.enabled = true,
|
|
this.width,
|
|
this.height = 48,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Color foregroundColor = Colors.black;
|
|
Color backgroundColor = Colors.black;
|
|
switch (style) {
|
|
case ButtonStyleMode.primary:
|
|
backgroundColor = Theme.of(context).colorScheme.primary;
|
|
foregroundColor = Theme.of(context).colorScheme.white;
|
|
break;
|
|
case ButtonStyleMode.secondary:
|
|
backgroundColor = Theme.of(context).colorScheme.secondCTA;
|
|
foregroundColor = Theme.of(context).colorScheme.text;
|
|
break;
|
|
case ButtonStyleMode.flat:
|
|
if (DesignConfig.isDark) {
|
|
backgroundColor = Theme.of(context).colorScheme.surface;
|
|
foregroundColor = Theme.of(context).colorScheme.white;
|
|
} else {
|
|
backgroundColor = Theme.of(context).colorScheme.surface;
|
|
foregroundColor = Theme.of(context).colorScheme.primary;
|
|
}
|
|
break;
|
|
default:
|
|
}
|
|
return SizedBox(
|
|
height: height,
|
|
width: width ?? double.infinity,
|
|
child: MaterialButton(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: DesignConfig.lowBorderRadius,
|
|
side: style == ButtonStyleMode.flat
|
|
? BorderSide(color: foregroundColor)
|
|
: BorderSide.none,
|
|
),
|
|
color: backgroundColor,
|
|
disabledColor: Theme.of(context).colorScheme.disabledBackground,
|
|
onPressed: !enabled
|
|
? null
|
|
: () {
|
|
FocusScope.of(context).unfocus();
|
|
onPressed?.call();
|
|
},
|
|
child: _childBuilder(foregroundColor, context),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget? _childBuilder(Color color, context) {
|
|
if (title != null) {
|
|
return FittedBox(
|
|
fit: BoxFit.scaleDown,
|
|
child: DidvanText(
|
|
title!,
|
|
color: enabled ? color : Theme.of(context).colorScheme.disabledText,
|
|
),
|
|
);
|
|
}
|
|
return null;
|
|
}
|
|
}
|