0

我想像FormBuilderTextField在第一个文本字段中一样左对齐第二个文本字段的标签。当我添加一个下拉列表时,标签被推到中心prefixIcon。我想把那个标签带到左边。

在此处输入图像描述

Padding(
  padding: EdgeInsets.only(top: 8, bottom: 8),
  child: FormBuilderTextField(
    controller: controller,
    name: name!,
    initialValue: initialValue,
    style: TextStyle(color: Colors.black),
    enabled: enabled,
    keyboardType: keyBoardType,
    decoration: InputDecoration(
      prefixIcon: Container(
        width: 120.0,
        child: FormBuilderDropdown(
          name: "countryList",
          iconSize: 0.0,
          decoration: InputDecoration(
            icon: null,
            labelStyle: TextStyle(
                color: enabled
                    ? Colors.black54
                    : Theme.of(context).disabledColor),
            contentPadding: EdgeInsets.all(8),
            enabledBorder: InputBorder.none,
          ),
          enabled: enabled,
          items: countries
              .map((Country country) => DropdownMenuItem(
                    value: country.id,
                    child: Row(
                      children: [
                        CachedNetworkImage(
                          width: 30,
                          height: 20,
                          imageUrl: country.photo!.path!,
                          imageBuilder: (context, imageProvider) =>
                              Container(
                            decoration: BoxDecoration(
                              image: DecorationImage(
                                  image: imageProvider, fit: BoxFit.fill),
                            ),
                          ),
                          placeholder: (context, url) =>
                              CircularProgressIndicator(),
                          errorWidget: (context, url, error) =>
                              Icon(Icons.error),
                        ),
                        SizedBox(
                          width: 10.0,
                        ),
                        Text("+${country.phoneCode}" ?? "")
                      ],
                    ),
                  ))
              .toList(),
        ),
      ),
      labelText: label,
      labelStyle: TextStyle(
          color:
              enabled ? Colors.black54 : Theme.of(context).disabledColor),
      contentPadding: EdgeInsets.all(16),
      focusedBorder: OutlineInputBorder(
        borderSide: BorderSide(color: Theme.of(context).primaryColor),
      ),
      border: new OutlineInputBorder(borderSide: new BorderSide()),
    ),
    validator: validator,
    obscureText: obscureText!,
  ),
);
4

1 回答 1

0

使用prefix而不是prefixIcon它应该解决你的情况。

于 2021-08-26T12:01:33.923 回答