TextformfieldFlutter改变形状时,没有值

isr3a4wc  于 2023-05-08  发布在  Flutter
关注(0)|答案(2)|浏览(128)

这是textFormField

当TextFormField没有值时,它看起来有一个不同的形状,当表单被提交并且用户没有填写textFormField时,它会像这样改变形状

我想textFormfield形状不改变,有什么解决方案吗?
这是我的代码:

Container(
              height: Sizes.screenHeight(context) * 0.13,
              width: Sizes.screenWidth(context) * 0.01,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  Container(
                    height: Sizes.screenHeight(context) * 0.06,
                    width: Sizes.screenWidth(context) * 0.4,
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(10),
                        border: Border.all(color: SporteevColors.black)),
                    child: Container(
                      margin: const EdgeInsets.only(left: 8, right: 8),
                      child: DropdownButtonFormField<String?>(
                        hint: const Text("Media Social"),
                        decoration: const InputDecoration(
                            enabledBorder: InputBorder.none,
                            focusedBorder: InputBorder.none),
                        borderRadius: BorderRadius.circular(10),
                        value: mediaSocial,
                        items: listMediaSocial,
                        isExpanded: true,
                        onChanged: (value) {
                          setState(() {
                            mediaSocial = value;
                          });
                        },
                      ),
                    ),
                  ),
                  SizedBox(
                    // color: Colors.black,
                    height: Sizes.screenHeight(context) * 0.062,
                    width: Sizes.screenWidth(context) * 0.4,
                    child: TextFormField(
                      keyboardType: mediaSocial == "WhatsApp"
                          ? TextInputType.number
                          : TextInputType.text,
                      validator: (value) {
                        if (value == null || value.isEmpty) {
                          return 'Please enter id';
                        }
                        return null;
                      },
                      onSaved: (value) => _data['contact'] = value,
                      controller: _idSocialMedia,
                      decoration: InputDecoration(
                        hintText: 'ID/username/No',
                        hintStyle:
                            const TextStyle(color: SporteevColors.grey),
                        contentPadding: const EdgeInsets.symmetric(
                            vertical: 20, horizontal: 20),
                        fillColor: Colors.white.withOpacity(0.9),
                        filled: true,
                        border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(10),
                          // borderSide: BorderSide.none,
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
ie3xauqp

ie3xauqp1#

您可以将其封装在SizedBox中,并为它设置固定的高度:

验证码:

Container(
  height: Sizes.screenHeight(context) * 0.13,
  width: Sizes.screenWidth(context) * 0.01,
  child: Row(
    mainAxisAlignment: MainAxisAlignment.spaceAround,
    children: [
      Container(
        height: Sizes.screenHeight(context) * 0.06,
        width: Sizes.screenWidth(context) * 0.4,
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(10),
            border: Border.all(color: SporteevColors.black)),
        child: Container(
          margin: const EdgeInsets.only(left: 8, right: 8),
          child: DropdownButtonFormField<String?>(
            // DropdownButtonFormField code here
          ),
        ),
      ),
      SizedBox(
        height: Sizes.screenHeight(context) * 0.062,
        width: Sizes.screenWidth(context) * 0.4,
        child: SizedBox(
          child: TextFormField(
            keyboardType: mediaSocial == "WhatsApp"
                ? TextInputType.number
                : TextInputType.text,
            validator: (value) {
              if (value == null || value.isEmpty) {
                return 'Please enter id';
              }
              return null;
            },
            onSaved: (value) => _data['contact'] = value,
            controller: _idSocialMedia,
            decoration: InputDecoration(
              // InputDecoration code here
            ),
          ),
        ),
      ),
    ],
  ),
),
daupos2t

daupos2t2#

因为你给了高度,高度会降低,所以不要使用固定大小或使用扩展小部件

相关问题