You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/new_views/common_widgets/app_filled_button.dart

136 lines
4.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/models/new_models/gas_refill_model.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
class AppFilledButton extends StatelessWidget {
final VoidCallback? onPressed;
final String label;
final bool maxWidth, loading;
final double? fontSize;
final bool showIcon;
final Widget? icon;
final Color? buttonColor;
final Color? textColor;
final bool showBorder;
final double radius;
final int height;
final double? width;
final bool disableButton;
const AppFilledButton(
{this.onPressed,
required this.label,
this.maxWidth = false,
this.showIcon = false,
this.icon,
this.fontSize,
this.loading = false,
this.height = 56,
this.width,
this.showBorder = false,
this.disableButton = false,
this.buttonColor,
this.textColor,
this.radius = 10,
Key? key})
: super(key: key);
@override
Widget build(BuildContext context) {
return AnimatedContainer(
duration: const Duration(milliseconds: 250),
height: height.toScreenHeight,
width: maxWidth ? double.infinity : width,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: disableButton
? context.isDark
? AppColor.neutral20
: AppColor.neutral140
: (buttonColor ?? AppColor.primary10),
border: showBorder ? Border.all(color: textColor ?? AppColor.background(context)) : null,
),
child: loading
? SizedBox(
width: 24.toScreenHeight,
height: 24.toScreenHeight,
child: CircularProgressIndicator(
color: textColor ?? AppColor.background(context),
strokeWidth: 2,
),
)
: showIcon && icon != null
? Row(mainAxisAlignment: MainAxisAlignment.center, children: [
icon!,
8.width,
label.heading6(context).custom(color: textColor ?? AppColor.background(context)),
])
: label.heading6(context).custom(
color: disableButton ? AppColor.neutral150 : (textColor ?? AppColor.background(context)),
align: TextAlign.center,
fontSize: fontSize ?? 16.toScreenWidth,
),
).onPress(disableButton ? null : (loading ? null : onPressed));
}
}
class AppTextButton extends StatelessWidget {
final VoidCallback? onPressed;
final String label;
final bool maxWidth, loading;
final double? fontSize;
final double? height;
final bool showIcon;
final String? iconString;
final Color? buttonColor;
final bool showBorder;
final double radius;
final bool disableButton;
const AppTextButton(
{this.onPressed,
required this.label,
this.maxWidth = false,
this.showIcon = false,
this.iconString,
this.fontSize,
this.height,
this.loading = false,
this.showBorder = false,
this.disableButton = false,
this.buttonColor,
this.radius = 35,
Key? key})
: super(key: key);
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
height: height,
width: label.length * 15,
alignment: Alignment.center,
decoration: BoxDecoration(
color: disableButton ? AppColor.disableFieldBackground(context) : buttonColor ?? AppColor.primary10,
borderRadius: BorderRadius.circular(radius),
),
child: Row(
spacing: 8,
mainAxisSize: MainAxisSize.min,
children: [
if (showIcon && iconString != null) iconString!.toSvgAsset(height: 20, width: 20, color: AppColor.icon2Color(context)),
Text(
label,
style: AppTextStyles.bodyText2.copyWith(color: AppColor.textStyleColor(context)),
),
],
),
).onPress(disableButton ? null : onPressed);
}
}