Untitled
unknown
plain_text
3 years ago
8.2 kB
11
Indexable
import 'package:base_architecture/core/constants/theme.dart';
import 'package:base_architecture/presentation/notifiers/theme_notifier.dart';
import 'package:base_architecture/presentation/resources/color_manager.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';
class ArabTextField extends StatelessWidget {
const ArabTextField({
Key? key,
required this.hintText,
required this.labelText,
required this.isRequired,
this.verifyEmail = false,
this.onIconPressed,
this.onEditingComplete,
this.onSaved,
this.textInputAction,
this.validator,
this.keyboardType,
this.initialValue,
this.iconData,
this.obscureText,
this.suffixIcon,
this.prefixIcon,
this.isFirst,
this.isLast,
this.style,
this.textAlign,
this.onChanged,
this.borderRadius,
this.controller,
this.isRaduis,
this.maxLengthEnforced,
this.maxLength,
this.maxLines,
this.svgpath = '',
this.onFieldSubmitted,
this.formatter,
}) : super(key: key);
final int? maxLines;
final bool isRequired;
final bool verifyEmail;
final TextInputAction? textInputAction;
final ValueChanged<String>? onFieldSubmitted;
final VoidCallback? onEditingComplete;
final ValueChanged<String?>? onSaved;
final FormFieldValidator<String?>? validator;
final TextInputType? keyboardType;
final String? initialValue;
final String hintText;
final TextAlign? textAlign;
final String labelText;
final TextStyle? style;
final IconData? iconData;
final String? svgpath;
final bool? obscureText;
final bool? isFirst;
final bool? isLast;
final Widget? suffixIcon;
final Widget? prefixIcon;
final void Function(String)? onChanged;
final BorderRadius? borderRadius;
final bool? isRaduis;
final bool? maxLengthEnforced;
final int? maxLength;
final List<TextInputFormatter>? formatter;
final VoidCallback? onIconPressed;
final TextEditingController? controller;
@override
Widget build(BuildContext context) {
Size mediaQuery = MediaQuery.of(context).size;
final ThemeNotifier themeNotifier = Provider.of<ThemeNotifier>(
context,
listen: true,
);
return Column(
children: <Widget>[
SizedBox(
width: mediaQuery.width,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Semantics(
container: true,
label: labelText.tr(),
child: ExcludeSemantics(
excluding: true,
child: RichText(
text: TextSpan(
text: labelText.tr(),
style: themeNotifier
.getTheme()
.textTheme
.headline2!
.copyWith(
color: themeNotifier.getTheme().shadowColor,
fontSize: 16,
),
children: <InlineSpan>[
if (isRequired == true)
TextSpan(
text: ' *',
style: GoogleFonts.tajawal(
color: HexColor.fromHex('#E83B69'),
fontSize: 13,
),
)
else
const TextSpan(text: ''),
],
),
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: TextFormField(
inputFormatters: formatter ?? <TextInputFormatter>[],
textInputAction: textInputAction,
initialValue: initialValue,
controller: controller,
keyboardType: keyboardType ?? TextInputType.text,
onSaved: onSaved,
onFieldSubmitted: onFieldSubmitted,
onEditingComplete: onEditingComplete,
onChanged: onChanged,
validator: validator,
cursorColor: themeNotifier.getTheme().hoverColor,
style: themeNotifier.getTheme().textTheme.headline2!.copyWith(
fontWeight: FontWeight.normal,
fontSize: 15,
color: themeNotifier.getTheme().hintColor),
obscureText: obscureText ?? false,
decoration: InputDecoration(
filled: true,
counterText: '',
contentPadding:
const EdgeInsets.symmetric(horizontal: 5, vertical: 0),
fillColor: themeNotifier.getTheme().focusColor,
errorStyle: GoogleFonts.tajawal(
fontSize: 12,
),
disabledBorder: OutlineInputBorder(
borderRadius: const BorderRadius.all(
Radius.circular(10),
),
borderSide: BorderSide(
color: themeNotifier.getTheme() == AppThemes().darkTheme
? Colors.transparent
: HexColor.fromHex('#E9EBEF'),
),
),
enabledBorder: OutlineInputBorder(
borderRadius: const BorderRadius.all(
Radius.circular(10),
),
borderSide: BorderSide(
color: themeNotifier.getTheme() == AppThemes().darkTheme
? Colors.transparent
: HexColor.fromHex('#E9EBEF'),
),
),
focusedBorder: OutlineInputBorder(
borderRadius: const BorderRadius.all(
Radius.circular(10),
),
borderSide: BorderSide(
color: themeNotifier.getTheme() == AppThemes().darkTheme
? Colors.transparent
: HexColor.fromHex('#E9EBEF'),
),
),
hintText: hintText.tr(),
alignLabelWithHint: true,
hintStyle: themeNotifier.getTheme().textTheme.headline2!.copyWith(
fontSize: 15,
color: themeNotifier.getTheme().hintColor,
),
border: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10),
),
),
suffixIconConstraints: BoxConstraints(
maxWidth: suffixIcon != null ? 81 : 1,
maxHeight: 50,
minHeight: 30,
minWidth: suffixIcon != null ? 30 : 0,
),
prefixIcon: prefixIcon,
suffixIcon: Visibility(
visible: svgpath != '' || svgpath != null,
child: Container(
child: suffixIcon,
),
),
),
maxLines: maxLines ?? 1,
maxLength: maxLength,
),
),
],
);
}
BorderRadius get buildBorderRadius {
if (isFirst != null && isFirst!) {
return const BorderRadius.vertical(
top: Radius.circular(10),
);
}
if (isLast != null && isLast!) {
return const BorderRadius.vertical(
bottom: Radius.circular(10),
);
}
if (isFirst != null && !isFirst! && isLast != null && !isLast!) {
return const BorderRadius.all(
Radius.circular(10),
);
}
return const BorderRadius.all(
Radius.circular(10),
);
}
double get topMargin {
if ((isFirst != null && isFirst!)) {
return 0;
} else if (isFirst == null) {
return 0;
} else {
return 0;
}
}
double get bottomMargin {
if ((isLast != null && isLast!)) {
return 10;
} else if (isLast == null) {
return 10;
} else {
return 0;
}
}
}
Editor is loading...