259 lines
5.1 KiB
Dart
259 lines
5.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../utils/color_constants.dart';
|
|
import '../utils/size_utils.dart';
|
|
|
|
class CustomRadioButton extends StatelessWidget {
|
|
CustomRadioButton(
|
|
{super.key, this.shape,
|
|
this.padding,
|
|
this.variant,
|
|
this.fontStyle,
|
|
this.alignment,
|
|
this.onChange,
|
|
this.isRightCheck = false,
|
|
this.iconSize,
|
|
this.value,
|
|
this.groupValue,
|
|
this.text,
|
|
this.width,
|
|
this.margin});
|
|
|
|
RadioShape? shape;
|
|
|
|
RadioPadding? padding;
|
|
|
|
RadioVariant? variant;
|
|
|
|
RadioFontStyle? fontStyle;
|
|
|
|
Alignment? alignment;
|
|
|
|
Function(String)? onChange;
|
|
|
|
bool? isRightCheck;
|
|
|
|
double? iconSize;
|
|
|
|
String? value;
|
|
|
|
String? groupValue;
|
|
|
|
String? text;
|
|
|
|
double? width;
|
|
|
|
EdgeInsetsGeometry? margin;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return alignment != null
|
|
? Align(
|
|
alignment: alignment ?? Alignment.center,
|
|
child: _buildRadioButtonWidget(),
|
|
)
|
|
: _buildRadioButtonWidget();
|
|
}
|
|
|
|
_buildRadioButtonWidget() {
|
|
return InkWell(
|
|
onTap: () {
|
|
onChange!(value!);
|
|
},
|
|
child: Container(
|
|
width: width,
|
|
margin: margin ?? EdgeInsets.zero,
|
|
padding: _setPadding(),
|
|
decoration: _buildDecoration(),
|
|
child: isRightCheck! ? getRightSideRadio() : getLeftSideRadio(),
|
|
),
|
|
);
|
|
}
|
|
|
|
_buildDecoration() {
|
|
return BoxDecoration(
|
|
color: _setColor(),
|
|
border: _setBorder(),
|
|
borderRadius: _setBorderRadius(),
|
|
);
|
|
}
|
|
|
|
Widget getRightSideRadio() {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(
|
|
right: 8,
|
|
),
|
|
child: getTextWidget(),
|
|
),
|
|
getRadioWidget(),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget getLeftSideRadio() {
|
|
return Row(
|
|
children: [
|
|
getRadioWidget(),
|
|
Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 8,
|
|
),
|
|
child: getTextWidget(),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget getTextWidget() {
|
|
return Text(
|
|
text ?? "",
|
|
textAlign: TextAlign.center,
|
|
style: _setFontStyle(),
|
|
);
|
|
}
|
|
|
|
Widget getRadioWidget() {
|
|
return SizedBox(
|
|
height: iconSize,
|
|
width: iconSize,
|
|
child: Radio<String>(
|
|
value: value ?? "",
|
|
groupValue: groupValue,
|
|
activeColor: ColorConstant.whiteA700,
|
|
onChanged: (value) {
|
|
onChange!(value!);
|
|
},
|
|
visualDensity: const VisualDensity(
|
|
vertical: -4,
|
|
horizontal: -4,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
_setFontStyle() {
|
|
switch (fontStyle) {
|
|
case RadioFontStyle.GilroyMedium16:
|
|
return TextStyle(
|
|
color: ColorConstant.blueA700,
|
|
fontSize: getFontSize(
|
|
16,
|
|
),
|
|
fontFamily: 'Gilroy',
|
|
fontWeight: FontWeight.w500,
|
|
);
|
|
case RadioFontStyle.GilroyMedium18:
|
|
return TextStyle(
|
|
color: ColorConstant.blueGray300,
|
|
fontSize: getFontSize(
|
|
18,
|
|
),
|
|
fontFamily: 'Gilroy',
|
|
fontWeight: FontWeight.w500,
|
|
);
|
|
case RadioFontStyle.GilroyRegular16:
|
|
return TextStyle(
|
|
color: ColorConstant.blueGray900,
|
|
fontSize: getFontSize(
|
|
16,
|
|
),
|
|
fontFamily: 'Gilroy',
|
|
fontWeight: FontWeight.w400,
|
|
);
|
|
default:
|
|
return TextStyle(
|
|
color: ColorConstant.blueGray400,
|
|
fontSize: getFontSize(
|
|
16,
|
|
),
|
|
fontFamily: 'Gilroy',
|
|
fontWeight: FontWeight.w500,
|
|
);
|
|
}
|
|
}
|
|
|
|
_setPadding() {
|
|
switch (padding) {
|
|
case RadioPadding.PaddingAll11:
|
|
return getPadding(
|
|
all: 11,
|
|
);
|
|
case RadioPadding.PaddingT1:
|
|
return getPadding(
|
|
top: 1,
|
|
bottom: 1,
|
|
);
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
_setColor() {
|
|
switch (variant) {
|
|
case RadioVariant.OutlineBluegray400:
|
|
return ColorConstant.whiteA700;
|
|
case RadioVariant.OutlineBlueA700:
|
|
return ColorConstant.whiteA700;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
_setBorder() {
|
|
switch (variant) {
|
|
case RadioVariant.OutlineBluegray400:
|
|
return Border.all(
|
|
color: ColorConstant.blueGray400,
|
|
width: getHorizontalSize(
|
|
1.00,
|
|
),
|
|
);
|
|
case RadioVariant.OutlineBlueA700:
|
|
return Border.all(
|
|
color: ColorConstant.blueA700,
|
|
width: getHorizontalSize(
|
|
1.00,
|
|
),
|
|
);
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
_setBorderRadius() {
|
|
switch (shape) {
|
|
case RadioShape.RoundedBorder6:
|
|
return BorderRadius.circular(
|
|
getHorizontalSize(
|
|
6.00,
|
|
),
|
|
);
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
enum RadioShape {
|
|
RoundedBorder6,
|
|
}
|
|
|
|
enum RadioPadding {
|
|
PaddingAll11,
|
|
PaddingT1,
|
|
}
|
|
|
|
enum RadioVariant {
|
|
OutlineBluegray400,
|
|
OutlineBlueA700,
|
|
}
|
|
|
|
enum RadioFontStyle {
|
|
GilroyMedium16Bluegray400,
|
|
GilroyMedium16,
|
|
GilroyMedium18,
|
|
GilroyRegular16,
|
|
}
|