【问题标题】:Left Align the labelText of FormBuilderTextField in FlutterFlutter中FormBuilderTextField的labelText左对齐
【发布时间】:2021-10-26 11:17:25
【问题描述】:

我想左对齐第二个文本字段的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!,
  ),
);

【问题讨论】:

  • 你能添加你的代码sn-p吗?
  • 添加你的代码sn-p
  • 已更新代码

标签: flutter flutter-form-builder


【解决方案1】:

使用prefix 而不是prefixIcon它应该可以解决您的问题。

【讨论】:

    猜你喜欢
    • 2020-08-28
    • 2020-09-06
    • 2019-03-09
    • 2021-09-28
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 1970-01-01
    相关资源
    最近更新 更多