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

151 lines
4.3 KiB
Dart

2 months ago
import 'package:flutter/material.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';
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
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,
// this.countryList = const [],
// this.onCountryChange,
2 months ago
}) : super(key: key);
@override
2 months ago
Widget build(BuildContext context) {
return Container(
padding: padding,
alignment: Alignment.center,
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
color: Colors.white,
borderRadius: isAllowRadius ? 15 : null,
side: isBorderAllowed ? BorderSide(color: 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),
],
),
),
],
),
);
}
2 months ago
2 months ago
Widget _buildLeadingIcon(BuildContext context) {
return Container(
height: 40,
width: 40,
margin: const EdgeInsets.only(right: 10),
padding: const EdgeInsets.all(8),
decoration: const BoxDecoration(color: Color(0xFFEFEFF0), borderRadius: BorderRadius.all(Radius.circular(10))),
child: Utils.buildSvgWithAssets(icon: leadingIcon!));
2 months ago
}
2 months ago
Widget _buildLabelText() {
return Text(
labelText,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: Color(0xff898A8D),
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: const TextStyle(
fontSize: 14,
height: 21 / 14,
fontWeight: FontWeight.w500,
color: Color(0xff2E3039),
letterSpacing: -0.2,
),
decoration: InputDecoration(
isDense: true,
hintText: hintText,
hintStyle: const TextStyle(
fontSize: 14,
height: 21 / 16,
fontWeight: FontWeight.w500,
color: Color(0xff898A8D),
letterSpacing: -0.2,
2 months ago
),
2 months ago
prefixIconConstraints: const BoxConstraints(minWidth: 45),
prefixIcon: prefix == null
? null
: Text(
"+" + prefix!,
style: const TextStyle(
fontSize: 14,
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
),
);
}
}