Files
fcs/lib/pages/widgets/input_text.dart
2024-02-19 17:06:36 +06:30

121 lines
4.3 KiB
Dart

import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/pages/main/model/language_model.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class InputText extends StatelessWidget {
final String? labelTextKey;
final IconData? iconData;
final TextEditingController? controller;
final FormFieldValidator<String>? validator;
final int maxLines;
final bool withBorder;
final Color? borderColor;
final TextInputType? textInputType;
final bool autoFocus;
final TextAlign textAlign;
final bool enabled;
final BoxConstraints? constraints;
final EdgeInsetsGeometry? contentPadding;
final bool? isDense;
const InputText(
{Key? key,
this.labelTextKey,
this.iconData,
this.controller,
this.validator,
this.maxLines = 1,
this.withBorder = false,
this.borderColor,
this.autoFocus = false,
this.textInputType,
this.enabled = true,
this.textAlign = TextAlign.start,
this.constraints,
this.contentPadding,
this.isDense})
: super(key: key);
@override
Widget build(BuildContext context) {
var languageModel = Provider.of<LanguageModel>(context);
return Padding(
padding: const EdgeInsets.only(top: 15.0, bottom: 5),
child: TextFormField(
enabled: enabled,
controller: controller,
autofocus: autoFocus,
cursorColor: primaryColor,
style: textStyle,
maxLines: maxLines,
keyboardType: textInputType,
textAlign: textAlign,
decoration: new InputDecoration(
isDense: isDense,
constraints: constraints,
contentPadding: contentPadding,
// hintText: '',
errorStyle: const TextStyle(color: dangerColor, fontSize: 12),
hintStyle: TextStyle(
height: 1.5,
),
labelText: labelTextKey == null
? null
: AppTranslations.of(context)!.text(labelTextKey!),
labelStyle: languageModel.isEng
? newLabelStyle(color: Colors.black54, fontSize: 20)
: newLabelStyleMM(color: Colors.black54, fontSize: 20),
icon: iconData == null
? null
: Icon(
iconData,
color: primaryColor,
),
enabledBorder: withBorder
? OutlineInputBorder(
borderSide: BorderSide(
color: borderColor ?? primaryColor, width: 1.0),
)
: UnderlineInputBorder(
borderSide: BorderSide(
color: borderColor ?? primaryColor, width: 1.0)),
focusedBorder: withBorder
? OutlineInputBorder(
borderSide: BorderSide(
color: borderColor ?? primaryColor, width: 1.0),
)
: UnderlineInputBorder(
borderSide: BorderSide(
color: borderColor ?? primaryColor, width: 1.0)),
disabledBorder: withBorder
? OutlineInputBorder(
borderSide: BorderSide(
color: borderColor ?? primaryColor, width: 1.0),
)
: UnderlineInputBorder(
borderSide: BorderSide(
color: borderColor ?? primaryColor, width: 1.0)),
errorBorder: withBorder
? OutlineInputBorder(
borderSide: BorderSide(
color: borderColor ?? dangerColor, width: 1.0),
)
: UnderlineInputBorder(
borderSide: BorderSide(
color: borderColor ?? dangerColor, width: 1.0)),
focusedErrorBorder: withBorder
? OutlineInputBorder(
borderSide: BorderSide(
color: borderColor ?? dangerColor, width: 1.0),
)
: UnderlineInputBorder(
borderSide: BorderSide(
color: borderColor ?? dangerColor, width: 1.0)),
),
validator: validator),
);
}
}