textfield

 avatar
unknown
dart
2 years ago
7.5 kB
2
Indexable
import 'package:base_architecture/presentation/notifiers/theme_notifier.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 = Provider.of<ThemeNotifier>(context, listen: true);
    return Column(
      children: [
        SizedBox(
          width: mediaQuery.width,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Semantics(
                container: true,
                label: labelText.tr(),
                child: ExcludeSemantics(
                  excluding: true,
                  child: RichText(
                    text: TextSpan(
                      text: labelText.tr(),
                      style: themeNotifier
                          .getTheme()
                          .textTheme
                          .headline4!
                          .copyWith(
                            fontSize: 16,
                            color: themeNotifier.getTheme().hoverColor,
                          ),
                      children: [
                        isRequired == true
                            ? TextSpan(
                                text: " *",
                                style: GoogleFonts.tajawal(
                                  color: themeNotifier.getTheme().canvasColor,
                                  fontSize: 13,
                                ),
                              )
                            : const TextSpan(text: ""),
                      ],
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
        Padding(
          padding: const EdgeInsets.symmetric(vertical: 8),
          child: TextFormField(
            inputFormatters: formatter ?? [],
            textInputAction: textInputAction,
            initialValue: initialValue,
            controller: controller,
            keyboardType: keyboardType ?? TextInputType.text,
            onSaved: onSaved,
            onFieldSubmitted: onFieldSubmitted,
            onEditingComplete: onEditingComplete,
            onChanged: onChanged,
            validator: validator,
            cursorColor: themeNotifier.getTheme().canvasColor,
            style: GoogleFonts.tajawal(
              fontWeight: FontWeight.normal,
              color: themeNotifier.getTheme().hoverColor,
              fontSize: 15,
            ),
            obscureText: obscureText ?? false,
            decoration: InputDecoration(
              counterText: "",
              contentPadding:
                  const EdgeInsets.symmetric(horizontal: 15, vertical: 14),
              fillColor: const Color(0xFFAEB4BF).withOpacity(0.1),
              errorStyle: GoogleFonts.tajawal(
                fontSize: 12,
              ),
              disabledBorder: OutlineInputBorder(
                borderRadius: const BorderRadius.all(
                  Radius.circular(10),
                ),
                borderSide: BorderSide(
                  color: themeNotifier.getTheme().shadowColor,
                ),
              ),
              enabledBorder: OutlineInputBorder(
                borderRadius: const BorderRadius.all(
                  Radius.circular(10),
                ),
                borderSide: BorderSide(
                  color: themeNotifier.getTheme().shadowColor,
                ),
              ),
              focusedBorder: OutlineInputBorder(
                borderRadius: const BorderRadius.all(
                  Radius.circular(10),
                ),
                borderSide: BorderSide(
                  color: themeNotifier.getTheme().shadowColor,
                ),
              ),
              hintText: hintText.tr(),
              alignLabelWithHint: true,
              hintStyle: GoogleFonts.tajawal(fontSize: 15, color: Colors.grey),
              border: const OutlineInputBorder(
                borderRadius: BorderRadius.all(
                  Radius.circular(10),
                ),
              ),
              suffixIconConstraints: const BoxConstraints(
                maxWidth: 81,
                maxHeight: 50,
                minHeight: 30,
                minWidth: 30,
              ),
              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...