Как установить fontSize для FormTextField таким же, когда onFocus - PullRequest
0 голосов
/ 06 ноября 2019

Я использую flutter_form_builder https://pub.dev/packages/flutter_form_builder,, и я хочу, чтобы labelStyle было одинаковым, когда FormTextField находится в фокусе или нет.

enter image description here

На данный момент моя форма выглядит как на картинке выше. Но, как вы можете видеть, некоторые метки имеют разные размеры, потому что они не заполнены. Как можно установить для него одинаковый fontSize?

Фрагмент из моей формы лошади выглядит так:

return SafeArea(
      child: Column(
        children: <Widget>[
          buildFormHeader(context, null, nextPage, true),
          buildFormHeaderTitle(context, 'Add general information'),
          Expanded(
              child: Container(
                  padding: const EdgeInsets.fromLTRB(20, 0, 20, 30),
                  child: FormBuilder(
                      key: _fbKey,
                      initialValue: getInformationValues(),
                      autovalidate: true,
                      child: ListView(
                        children: <Widget>[
                          FormBuilderCustomField(attribute: "type", formField: FormConstants.horseTypeForm(typeController, getInformationValues(), _horseTypeValues, validateHorsePage)),
                          FormConstants.horseNameForm(checkUserValue),
                          FormConstants.birthDatePicker('birthdate', true),
                          FormBuilderCustomField(attribute: "studbook", formField: FormConstants.studbookForm(studbookController, _informationJson, _horseStudbookValues, validateHorsePage)),
                          FormBuilderCustomField(attribute: "gender", formField: FormConstants.genderForm(genderController, _informationJson, _horseGenderValues, validateHorsePage)),
                          FormBuilderCustomField(attribute: "colour", formField: FormConstants.horseColourForm(horseColourController, _informationJson, _horseColourValues, validateHorsePage)),
                        ],
                      )))),
        ],
      ),
    );

Мой horseNameForm, например:

  static final formLabelStyle = TextStyle(color: Colors.black87, fontWeight: FontWeight.bold, fontSize: 14);
  static final formTextStyle = TextStyle(
    color: Colors.grey,
  );
  static final contentPadding = const EdgeInsets.symmetric(vertical: 30.0); 
      static FormBuilderTextField horseNameForm(checkUserValue) {
        return FormBuilderTextField(
          attribute: "name",
          decoration: InputDecoration(labelText: "Name", hintText: 'Add name', labelStyle: formLabelStyle, hintStyle: formTextStyle, contentPadding: contentPadding),
          validators: [
            FormBuilderValidators.required(errorText: "Name is required"),
            (value) => checkUserValue(value)
                ? "Horse already in use with same name and birthyear "
                    "and studbook"
                : null
          ],
        );
      }

А селектор племенной книги выглядит так:

  static FormBuilderSingleSelect studbookForm(controller, initialValue, data, save) {
    return FormBuilderSingleSelect(
        initialValue: initialValue != null ? initialValue['studbook'] : null,
        inputText: 'Studbook',
        titleText: 'Select studbook',
        maxLength: 1,
        controller: controller,
        dataSource: data,
        textField: 'name',
        valueField: 'code',
        filterable: true,
        required: true,
        saveValidation: save,
        validators: [FormBuilderValidators.required(errorText: 'Studbook is required')],
        labelStyle: formLabelStyle,
        hintStyle: formTextStyle,
        contentPadding: contentPadding);
  }

Здесь FormBuilderSingleSelect также содержит TextFormField, который необходимо обновить, чтобы онтот же размер, когда TextFormField сфокусирован или нет. Теперь, когда у вас есть что-то выбрать, ярлык меняется на меньший размер. Как установить, чтобы размер шрифта при выборе элемента не изменялся, и можно ли отображать заполнитель, пока значение не выбрано / не заполнено?

...