import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

// OWNER : Ibrahim albitar
// DATE : 19-04-2020
// DESCRIPTION : Custom Text Form Field for app.

class AppTextFormField extends FormField<String> {

  AppTextFormField({
    FormFieldSetter<String> onSaved,
    String inputFormatter,
    FormFieldValidator<String> validator,
    ValueChanged<String> onChanged,
    GestureTapCallback onTap,
    TextEditingController controller,
    bool autovalidate = true,
    TextInputType textInputType,
    String hintText,
    FocusNode focusNode,
    TextInputAction textInputAction,
    ValueChanged<String> onFieldSubmitted,
  }) : super(
    onSaved: onSaved,
    validator: validator,
    autovalidate: autovalidate,
    builder: (FormFieldState<String> state) {
      return Column(
        children: <Widget>[
          TextFormField(
          focusNode: focusNode,
          keyboardType: textInputType,
          inputFormatters: [WhitelistingTextInputFormatter(RegExp(inputFormatter)),],
          onChanged: onChanged?? (value){
            state.didChange(value);
          },
          textInputAction: textInputAction,
          onFieldSubmitted: onFieldSubmitted,
          decoration: InputDecoration(
              hintText: hintText,
              hintStyle: TextStyle(fontSize: SizeConfig.textMultiplier * 2),
              enabledBorder: OutlineInputBorder(
                borderRadius: BorderRadius.all(Radius.circular(10)),
                borderSide: BorderSide(color: Color(0xff707070)),
              ),
              focusedBorder: OutlineInputBorder(
                borderRadius: BorderRadius.all(Radius.circular(10)),
              )
              //BorderRadius.all(Radius.circular(20));
              ),
              onTap: onTap,
              controller: controller,  
    ),
    state.hasError?
        Text(
          state.errorText,
          style: TextStyle(
            color: Colors.red
          ),
        ) :
        Container()
        ],
      );
    }
  );
}
