forked from eatvio/eatvio_app
refactor(diary): Refactoring metrics for CustomOutlinedButton
This commit is contained in:
@@ -34,91 +34,143 @@ class CustomTextFormField extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
final Alignment? alignment;
|
final Alignment? alignment;
|
||||||
|
|
||||||
final double? width;
|
final double? width;
|
||||||
|
|
||||||
final TextEditingController? controller;
|
final TextEditingController? controller;
|
||||||
|
|
||||||
final FocusNode? focusNode;
|
final FocusNode? focusNode;
|
||||||
|
|
||||||
final bool? autofocus;
|
final bool? autofocus;
|
||||||
|
|
||||||
final TextStyle? textStyle;
|
final TextStyle? textStyle;
|
||||||
|
|
||||||
final bool? obscureText;
|
final bool? obscureText;
|
||||||
|
|
||||||
final List<TextInputFormatter>? inputFormatters;
|
final List<TextInputFormatter>? inputFormatters;
|
||||||
|
|
||||||
final TextInputAction? textInputAction;
|
final TextInputAction? textInputAction;
|
||||||
|
|
||||||
final TextInputType? textInputType;
|
final TextInputType? textInputType;
|
||||||
|
|
||||||
final int? maxLines;
|
final int? maxLines;
|
||||||
|
|
||||||
final String? hintText;
|
final String? hintText;
|
||||||
|
|
||||||
final TextStyle? hintStyle;
|
final TextStyle? hintStyle;
|
||||||
|
|
||||||
final Widget? prefix;
|
final Widget? prefix;
|
||||||
|
|
||||||
final BoxConstraints? prefixConstraints;
|
final BoxConstraints? prefixConstraints;
|
||||||
|
|
||||||
final Widget? suffix;
|
final Widget? suffix;
|
||||||
|
|
||||||
final BoxConstraints? suffixConstraints;
|
final BoxConstraints? suffixConstraints;
|
||||||
|
|
||||||
final EdgeInsets? contentPadding;
|
final EdgeInsets? contentPadding;
|
||||||
|
|
||||||
final InputBorder? borderDecoration;
|
final InputBorder? borderDecoration;
|
||||||
|
|
||||||
final Color? fillColor;
|
final Color? fillColor;
|
||||||
|
|
||||||
final bool? filled;
|
final bool? filled;
|
||||||
|
|
||||||
final TextInputType? keyboardType;
|
final TextInputType? keyboardType;
|
||||||
|
|
||||||
final FormFieldValidator<String>? validator;
|
final FormFieldValidator<String>? validator;
|
||||||
|
|
||||||
final void Function(String?)? onSaved;
|
final void Function(String?)? onSaved;
|
||||||
|
|
||||||
To resolve the error "Avoid returning widgets from a getter," you can refactor the textFormFieldWidget and decoration getters into regular methods and then call those methods within the build method. Here's the refactored code:
|
|
||||||
|
|
||||||
dart
|
|
||||||
|
|
||||||
class CustomTextFormField extends StatelessWidget {
|
|
||||||
// ... other properties remain the same
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return alignment != null
|
return alignment != null
|
||||||
? Align(
|
? Align(
|
||||||
alignment: alignment ?? Alignment.center,
|
alignment: alignment ?? Alignment.center,
|
||||||
child: _buildTextFormFieldWidget(),
|
child: SizedBox(
|
||||||
|
width: width ?? double.maxFinite,
|
||||||
|
child: TextFormField(
|
||||||
|
controller: controller,
|
||||||
|
focusNode: focusNode ?? FocusNode(),
|
||||||
|
autofocus: autofocus!,
|
||||||
|
style: textStyle ?? theme.textTheme.titleMedium,
|
||||||
|
obscureText: obscureText!,
|
||||||
|
textInputAction: textInputAction,
|
||||||
|
maxLines: maxLines ?? 1,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: hintText ?? "",
|
||||||
|
hintStyle: hintStyle ?? theme.textTheme.bodyLarge,
|
||||||
|
prefixIcon: prefix,
|
||||||
|
prefixIconConstraints: prefixConstraints,
|
||||||
|
suffixIcon: suffix,
|
||||||
|
suffixIconConstraints: suffixConstraints,
|
||||||
|
isDense: true,
|
||||||
|
contentPadding: contentPadding ?? EdgeInsets.all(6.h),
|
||||||
|
fillColor: fillColor ?? theme.colorScheme.onPrimary,
|
||||||
|
filled: filled,
|
||||||
|
border: borderDecoration ??
|
||||||
|
OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8.h),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: appTheme.blueA400,
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
enabledBorder: borderDecoration ??
|
||||||
|
OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8.h),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: appTheme.blueA400,
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
focusedBorder: borderDecoration ??
|
||||||
|
OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8.h),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: appTheme.blueA400,
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
keyboardType: keyboardType,
|
||||||
|
validator: validator,
|
||||||
|
onSaved: onSaved,
|
||||||
|
inputFormatters: inputFormatters,
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
: _buildTextFormFieldWidget();
|
: SizedBox(
|
||||||
|
width: width ?? double.maxFinite,
|
||||||
|
child: TextFormField(
|
||||||
|
controller: controller,
|
||||||
|
focusNode: focusNode ?? FocusNode(),
|
||||||
|
autofocus: autofocus!,
|
||||||
|
style: textStyle ?? theme.textTheme.titleMedium,
|
||||||
|
obscureText: obscureText!,
|
||||||
|
textInputAction: textInputAction,
|
||||||
|
maxLines: maxLines ?? 1,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: hintText ?? "",
|
||||||
|
hintStyle: hintStyle ?? theme.textTheme.bodyLarge,
|
||||||
|
prefixIcon: prefix,
|
||||||
|
prefixIconConstraints: prefixConstraints,
|
||||||
|
suffixIcon: suffix,
|
||||||
|
suffixIconConstraints: suffixConstraints,
|
||||||
|
isDense: true,
|
||||||
|
contentPadding: contentPadding ?? EdgeInsets.all(6.h),
|
||||||
|
fillColor: fillColor ?? theme.colorScheme.onPrimary,
|
||||||
|
filled: filled,
|
||||||
|
border: borderDecoration ??
|
||||||
|
OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8.h),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: appTheme.blueA400,
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
enabledBorder: borderDecoration ??
|
||||||
|
OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8.h),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: appTheme.blueA400,
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
focusedBorder: borderDecoration ??
|
||||||
|
OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8.h),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: appTheme.blueA400,
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
keyboardType: keyboardType,
|
||||||
|
validator: validator,
|
||||||
|
onSaved: onSaved,
|
||||||
|
inputFormatters: inputFormatters,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Widget _buildTextFormFieldWidget() {
|
/* InputDecoration _buildInputDecoration() {
|
||||||
return SizedBox(
|
|
||||||
width: width ?? double.maxFinite,
|
|
||||||
child: TextFormField(
|
|
||||||
controller: controller,
|
|
||||||
focusNode: focusNode ?? FocusNode(),
|
|
||||||
autofocus: autofocus!,
|
|
||||||
style: textStyle ?? theme.textTheme.titleMedium,
|
|
||||||
obscureText: obscureText!,
|
|
||||||
textInputAction: textInputAction,
|
|
||||||
maxLines: maxLines ?? 1,
|
|
||||||
decoration: _buildInputDecoration(),
|
|
||||||
validator: validator,
|
|
||||||
keyboardType: keyboardType,
|
|
||||||
onSaved: onSaved,
|
|
||||||
inputFormatters: inputFormatters,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
InputDecoration _buildInputDecoration() {
|
|
||||||
return InputDecoration(
|
return InputDecoration(
|
||||||
hintText: hintText ?? "",
|
hintText: hintText ?? "",
|
||||||
hintStyle: hintStyle ?? theme.textTheme.bodyLarge,
|
hintStyle: hintStyle ?? theme.textTheme.bodyLarge,
|
||||||
@@ -156,4 +208,4 @@ class CustomTextFormField extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
Reference in New Issue
Block a user