initial commit
This commit is contained in:
195
lib/application/component/text_form/text_form_view.dart
Normal file
195
lib/application/component/text_form/text_form_view.dart
Normal file
@@ -0,0 +1,195 @@
|
||||
import 'package:cims_apps/application/theme/color_palette.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:remove_emoji_input_formatter/remove_emoji_input_formatter.dart';
|
||||
|
||||
class TextFormView extends StatelessWidget {
|
||||
final String name;
|
||||
final String? helperText;
|
||||
final String? initialValue;
|
||||
final VoidCallback? onTap;
|
||||
final VoidCallback? onSubmit;
|
||||
final bool enabled;
|
||||
final bool readOnly;
|
||||
final String? hintText, errorText;
|
||||
final TextEditingController? ctrl;
|
||||
final Widget? suffixIcon, suffixLable;
|
||||
final Widget? prefixIcon;
|
||||
final TextInputType? keyboardType;
|
||||
final FormFieldValidator<String>? validator;
|
||||
final bool obscureText;
|
||||
final int? maxLength;
|
||||
final ValueChanged<String>? onChanged;
|
||||
final List<TextInputFormatter>? inputFormatters;
|
||||
final TextStyle? errorStyle, hintTextStyle;
|
||||
final _borderRadius = const BorderRadius.all(Radius.circular(10));
|
||||
final Color? enabledborderColor;
|
||||
final Color? focusedBorderColor;
|
||||
final bool textrea, isTextAlignCenter;
|
||||
final Widget? trailingTitleWidget;
|
||||
final BoxConstraints? suffixIconConstraints;
|
||||
final BoxConstraints? preffixIconConstraints;
|
||||
final bool disableColor;
|
||||
final Color? disabledborderColor;
|
||||
final bool? enableInteractiveSelection;
|
||||
final Color? fontColorDisabled;
|
||||
final FocusNode? focusNode;
|
||||
|
||||
// ignore: prefer_const_constructors_in_immutables
|
||||
TextFormView(
|
||||
{Key? key,
|
||||
required this.name,
|
||||
this.helperText,
|
||||
this.onTap,
|
||||
this.fontColorDisabled,
|
||||
this.enabledborderColor,
|
||||
this.disabledborderColor,
|
||||
this.initialValue,
|
||||
this.enabled = true,
|
||||
this.readOnly = false,
|
||||
this.obscureText = false,
|
||||
this.hintText,
|
||||
this.hintTextStyle,
|
||||
this.suffixIcon,
|
||||
this.suffixLable,
|
||||
this.prefixIcon,
|
||||
this.keyboardType,
|
||||
this.ctrl,
|
||||
this.focusedBorderColor,
|
||||
this.validator,
|
||||
this.maxLength,
|
||||
this.onChanged,
|
||||
this.inputFormatters,
|
||||
this.onSubmit,
|
||||
this.textrea = false,
|
||||
this.errorText,
|
||||
this.errorStyle,
|
||||
this.trailingTitleWidget,
|
||||
this.suffixIconConstraints,
|
||||
this.preffixIconConstraints,
|
||||
this.disableColor = false,
|
||||
this.enableInteractiveSelection = true,
|
||||
this.focusNode,
|
||||
this.isTextAlignCenter = false})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (inputFormatters != null && maxLength != null) {
|
||||
inputFormatters?.add(LengthLimitingTextInputFormatter(maxLength));
|
||||
}
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
name.isNotEmpty
|
||||
? validator != null
|
||||
? Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
name,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
color: ColorPalette.greyLight,
|
||||
),
|
||||
),
|
||||
suffixLable ??
|
||||
const Text(
|
||||
" * ",
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Text(
|
||||
name,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
),
|
||||
)
|
||||
: const SizedBox(),
|
||||
trailingTitleWidget ?? const SizedBox(),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8.0),
|
||||
TextFormField(
|
||||
focusNode: focusNode,
|
||||
onTapOutside: (event) => FocusScope.of(context).unfocus(),
|
||||
minLines: textrea ? 8 : 1,
|
||||
maxLines: textrea ? null : 1,
|
||||
initialValue: initialValue,
|
||||
enabled: enabled,
|
||||
controller: ctrl,
|
||||
// maxLength: maxLength,
|
||||
keyboardType: keyboardType,
|
||||
onTap: onTap,
|
||||
onEditingComplete: onSubmit,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
color: fontColorDisabled ?? Colors.black,
|
||||
),
|
||||
readOnly: readOnly,
|
||||
validator: validator,
|
||||
obscureText: obscureText,
|
||||
onChanged: onChanged,
|
||||
inputFormatters: inputFormatters ??
|
||||
[
|
||||
RemoveEmojiInputFormatter(),
|
||||
if (maxLength != null)
|
||||
LengthLimitingTextInputFormatter(maxLength)
|
||||
],
|
||||
enableInteractiveSelection: enableInteractiveSelection,
|
||||
textAlign: isTextAlignCenter ? TextAlign.center : TextAlign.left,
|
||||
decoration: InputDecoration(
|
||||
helperText: helperText,
|
||||
errorStyle: errorStyle,
|
||||
errorText: errorText,
|
||||
errorMaxLines: 2,
|
||||
hintStyle: hintTextStyle ??
|
||||
const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey,
|
||||
fontWeight: FontWeight.normal,
|
||||
),
|
||||
isDense: true,
|
||||
hintText: hintText,
|
||||
filled: true,
|
||||
fillColor: enabled && disableColor == false
|
||||
? Colors.white
|
||||
: const Color.fromARGB(255, 233, 236, 239),
|
||||
disabledBorder: OutlineInputBorder(
|
||||
borderRadius: _borderRadius,
|
||||
borderSide: BorderSide(
|
||||
color: disabledborderColor ?? ColorPalette.greyFont,
|
||||
),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: _borderRadius,
|
||||
borderSide: BorderSide(
|
||||
color: enabledborderColor ?? ColorPalette.greyBase,
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: _borderRadius,
|
||||
borderSide: BorderSide(
|
||||
color: focusedBorderColor ?? ColorPalette.greyBase,
|
||||
),
|
||||
),
|
||||
border: OutlineInputBorder(borderRadius: _borderRadius),
|
||||
suffixIcon: suffixIcon,
|
||||
prefixIcon: prefixIcon,
|
||||
suffixIconConstraints: suffixIconConstraints,
|
||||
prefixIconConstraints: preffixIconConstraints,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user