键盘打开时向上推表单项

问题描述 投票:0回答:0

我在 flutter 中创建了一个带有一些文本字段的表单。项目数量太多,以免键盘溢出项目。

我添加了一个列表视图来给它空间,让它有向上滚动的空间,但是当它被选中时,键盘不会将它向上推以保持表单域可见。

关于此的旁注:屏幕中的标题是静态标题,这意味着它在所有页面上保持相同。这是在 main.dart 中的一个列中完成的,这也是为什么我因为 ListView(Expanded 也不起作用)而溢出的原因。

我怎样才能让它滚动?

contact.dart

Column(
      children: [
        Text(
          'Neem contact op',
          style: TextStyle(
              fontFamily: kFontFamily,
              color: kDarkGreen,
              fontSize: containerHeight(context) * 0.05),
        ),
        Padding(
          padding:
              EdgeInsets.symmetric(horizontal: displayWidth(context) * 0.05),
          child: Form(
            child: Column(
              children: [
                TextFormField(
                  keyboardType: TextInputType.name,
                  textInputAction: TextInputAction.next,
                  validator: (value) {
                    if (value!.isEmpty) {
                      return 'Geef je naam op';
                    }
                    return null;
                  },
                  decoration: const InputDecoration(
                    label: Text('Naam'),
                  ),
                ),
                TextFormField(
                  focusNode: telephoneFocusNode,
                  keyboardType: TextInputType.phone,
                  textInputAction: TextInputAction.next,
                  validator: (value) {
                    if (value!.isEmpty) {
                      return 'Geef je telefoon nummer op';
                    }
                    return null;
                  },
                  decoration: const InputDecoration(
                    label: Text('Telefoon nummer'),
                  ),
                ),
                TextFormField(
                  keyboardType: TextInputType.emailAddress,
                  decoration: const InputDecoration(
                    label: Text('E-mail adres'),
                  ),
                ),
                TextFormField(
                  keyboardType: TextInputType.multiline,
                  onFieldSubmitted: (_) {
                    _submitForm();
                  },
                  maxLines: 3,
                  decoration: const InputDecoration(
                    label: Text('Bericht'),
                  ),
                ),
                TextFormField(
                  keyboardType: TextInputType.multiline,
                  onFieldSubmitted: (_) {
                    _submitForm();
                  },
                  maxLines: 3,
                  decoration: const InputDecoration(
                    label: Text('Bericht'),
                  ),
                ),
                Container(height: 50, child: Text('Button'))
              ],
            ),
          ),
        ),
      ],
    );

我需要重构它以缩短代码,我首先需要一个解决方案;)

flutter
© www.soinside.com 2019 - 2024. All rights reserved.