flutter 我想更改TextFormField构件的高度,但不在Sizedbox构件中换行

0x6upsns  于 2023-05-19  发布在  Flutter
关注(0)|答案(1)|浏览(244)
Expanded(
                            child: Padding(
                              padding: const EdgeInsets.all(8.0),
                              child: TextFormField(
                                keyboardType: TextInputType.text,
                                controller: addressController,
                                decoration: const InputDecoration(
                                    hintText: 'Address',
                                    border: OutlineInputBorder(),
                                    enabledBorder: OutlineInputBorder(
                                      borderSide: BorderSide(
                                          color: Colors.black, width: 2.0),
                                    )),
                                validator: (value) {
                                  if (value!.isEmpty) {
                                    return 'Please enter your address';
                                  }
                                  return null;
                                },
                                onSaved: (value) {
                                  _address = value;
                                },
                              ),
                            ),
                          ),

我想改变高度的TEXTFORMFIELD,但当验证它改变它的高度。我 Package TextFormField在SizedBox但当验证是其变化的高度

zqdjd7g9

zqdjd7g91#

使用ContentPadding属性并设置为您的身高:

Expanded(
    child: Padding(
      padding: const EdgeInsets.all(8.0),
      child: TextFormField(
        keyboardType: TextInputType.name,
        // initialValue: sp.name.toString().split(' ').first,
        controller: firstNameController,
        decoration: const InputDecoration(
          contentPadding: EdgeInsets.symmetric(vertical: 10.0),
            hintText: 'First name',
            border: OutlineInputBorder(),
            errorBorder: OutlineInputBorder(
              borderSide:
                  BorderSide(color: Colors.red, width: 2.0),
            ),
            enabledBorder: OutlineInputBorder(
              borderSide: BorderSide(
                  color: Colors.black, width: 2.0),
            )),
        validator: (value) {
          if (value!.isEmpty) {
            return 'Please enter your first name';
          }
          return null;
        },
        onSaved: (value) {
          _firstName = value;
        },
      ),
    ),
  ),

相关问题