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.
HMG_Patient_App_New/lib/widgets/input_widget.dart

181 lines
5.3 KiB
Dart

2 months ago
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/app_export.dart';
2 months ago
import 'package:hmg_patient_app_new/core/utils/utils.dart';
2 months ago
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
2 months ago
2 months ago
// TODO: Import AppColors if bgRedColor is defined there
// import 'package:hmg_patient_app_new/core/ui_utils/app_colors.dart';
2 months ago
class TextInputWidget extends StatelessWidget {
2 months ago
final String labelText;
2 months ago
final String hintText;
final TextEditingController? controller;
final Function(String?)? onChange;
final String? prefix;
2 months ago
final bool isEnable;
2 months ago
final bool isBorderAllowed;
final bool isAllowRadius;
final bool isReadOnly;
final TextInputType keyboardType;
2 months ago
final FocusNode? focusNode;
2 months ago
final bool autoFocus;
final EdgeInsetsGeometry? padding;
final bool isAllowLeadingIcon;
final String? leadingIcon;
final bool isCountryDropDown;
2 months ago
final bool hasError;
final String? errorMessage;
2 months ago
2 months ago
// final List<Country> countryList;
// final Function(Country)? onCountryChange;
const TextInputWidget({
2 months ago
Key? key,
2 months ago
required this.labelText,
required this.hintText,
this.controller,
2 months ago
this.onChange,
2 months ago
this.prefix,
this.isEnable = true,
this.isBorderAllowed = true,
this.isAllowRadius = true,
this.isReadOnly = false,
this.keyboardType = TextInputType.number,
2 months ago
this.focusNode,
2 months ago
this.autoFocus = false,
this.padding,
this.isAllowLeadingIcon = false,
this.leadingIcon,
this.isCountryDropDown = false,
2 months ago
this.hasError = false,
this.errorMessage,
2 months ago
// this.countryList = const [],
// this.onCountryChange,
2 months ago
}) : super(key: key);
@override
2 months ago
Widget build(BuildContext context) {
final errorColor = AppColors.primaryRedColor;
2 months ago
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: padding,
alignment: Alignment.center,
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
color: Colors.white,
borderRadius: isAllowRadius ? 12 : null,
2 months ago
side: isBorderAllowed ? BorderSide(color: hasError ? errorColor : const Color(0xffefefef), width: 1) : null,
),
child: Row(
textDirection: Directionality.of(context),
children: [
if (isAllowLeadingIcon && leadingIcon != null) _buildLeadingIcon(context),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildLabelText(),
_buildTextField(context),
],
),
),
],
),
),
if (hasError && errorMessage != null)
Padding(
padding: EdgeInsets.only(top: 4.h, left: 12.h), // Adjust padding as needed
2 months ago
child: Text(
errorMessage!,
style: TextStyle(
color: errorColor,
fontSize: 12.fSize,
2 months ago
),
2 months ago
),
),
2 months ago
],
2 months ago
);
}
2 months ago
2 months ago
Widget _buildLeadingIcon(BuildContext context) {
return Container(
height: 40.h,
width: 40.h,
margin: EdgeInsets.only(right: 10.h),
padding: EdgeInsets.all(8.h),
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
borderRadius: 10.h,
color: AppColors.greyColor,
),
2 months ago
child: Utils.buildSvgWithAssets(icon: leadingIcon!));
2 months ago
}
2 months ago
Widget _buildLabelText() {
return Text(
labelText,
style: TextStyle(
fontSize: 12.fSize,
2 months ago
fontWeight: FontWeight.w500,
color: AppColors.inputLabelTextColor,
2 months ago
letterSpacing: -0.2,
height: 18 / 12,
),
);
2 months ago
}
2 months ago
Widget _buildTextField(BuildContext context) {
return TextField(
enabled: isEnable,
scrollPadding: EdgeInsets.zero,
keyboardType: keyboardType,
controller: controller,
readOnly: isReadOnly,
textAlignVertical: TextAlignVertical.top,
textAlign: TextAlign.left,
textDirection: TextDirection.ltr,
onChanged: onChange,
focusNode: focusNode,
autofocus: autoFocus,
style: TextStyle(
fontSize: 14.fSize,
2 months ago
height: 21 / 14,
fontWeight: FontWeight.w500,
color: AppColors.textColor,
2 months ago
letterSpacing: -0.2,
),
decoration: InputDecoration(
isDense: true,
hintText: hintText,
hintStyle: TextStyle(
fontSize: 14.fSize,
2 months ago
height: 21 / 16,
fontWeight: FontWeight.w500,
color: Color(0xff898A8D),
letterSpacing: -0.2,
2 months ago
),
prefixIconConstraints: BoxConstraints(minWidth: 45.h),
2 months ago
prefixIcon: prefix == null
? null
: Text(
"+" + prefix!,
style: TextStyle(
fontSize: 14.fSize,
2 months ago
height: 21 / 14,
fontWeight: FontWeight.w500,
color: Color(0xff2E303A),
letterSpacing: -0.2,
),
2 months ago
),
2 months ago
contentPadding: EdgeInsets.zero,
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
2 months ago
),
);
}
}