67 lines
1.9 KiB
Dart
67 lines
1.9 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/widgets/didvan/text.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class DidvanButton extends StatelessWidget {
|
|
final VoidCallback? onPressed;
|
|
final String? title;
|
|
final ButtonStyleMode style;
|
|
const DidvanButton({
|
|
Key? key,
|
|
this.onPressed,
|
|
this.title,
|
|
this.style = ButtonStyleMode.primary,
|
|
}) : 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:
|
|
backgroundColor = Theme.of(context).colorScheme.surface;
|
|
foregroundColor = Theme.of(context).colorScheme.white;
|
|
break;
|
|
default:
|
|
}
|
|
|
|
return SizedBox(
|
|
height: 48,
|
|
width: double.infinity,
|
|
child: MaterialButton(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: DesignConfig.lowBorderRadius,
|
|
side: style == ButtonStyleMode.flat
|
|
? BorderSide(color: foregroundColor)
|
|
: BorderSide.none,
|
|
),
|
|
color: backgroundColor,
|
|
onPressed: () {
|
|
FocusScope.of(context).unfocus();
|
|
onPressed?.call();
|
|
},
|
|
child: _childBuilder(foregroundColor),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget? _childBuilder(Color color) {
|
|
if (title != null) {
|
|
return DidvanText(
|
|
title!,
|
|
color: color,
|
|
);
|
|
}
|
|
}
|
|
}
|