【问题标题】:Keyboard hides input field in flutter键盘在颤动中隐藏输入字段
【发布时间】:2020-06-11 10:10:19
【问题描述】:

我已经看到这个问题被问了很多次,但没有一个解决方案对我有用。在下面的代码中,当单击bio 输入字段时,键盘会与该字段重叠。我尝试了resizeToAvoidBottomInset: true,有和没有SingleChildScrollView,但行为并没有改变。

Scaffold(
        resizeToAvoidBottomInset: false,
        appBar: ...
        body: SingleChildScrollView(child:
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 110, vertical: 16),
          child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                SizedBox(height: 40),
                Text('Username'),
                TextFormField(

                  controller: userName,
                  textAlign: TextAlign.left,
                ),
                Text('Screen name'),
                TextFormField(

                  controller: screenName,
                  textAlign: TextAlign.left,
                ),
                Text('Bio'),
                TextFormField(

                  controller: bio,
                  textAlign: TextAlign.left,
                ),

更新: 我创建了一个可以正常工作的空应用程序。所以代码似乎是正确的。我比较了AndroidManifest.xml。行是一样的:

<activity
    android:name=".MainActivity"
    android:launchMode="singleTop"
    android:theme="@style/LaunchTheme"
    android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
    android:hardwareAccelerated="true"
    android:windowSoftInputMode="adjustResize">

有人知道有什么不同吗?

【问题讨论】:

    标签: flutter


    【解决方案1】:

    我已经尝试过这段代码,它工作正常。

    Scaffold(
            resizeToAvoidBottomInset: false,
            body: SingleChildScrollView(child:
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 110, vertical: 16),
              child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    SizedBox(height: 40),
                    Text('Username'),
                    TextFormField(
                      textAlign: TextAlign.left,
                    ),
                    Text('Screen name'),
                    TextFormField(
                      textAlign: TextAlign.left,
                    ),
                    Text('Bio'),
                    TextFormField(
                      textAlign: TextAlign.left,
                    ),]))));
    

    如果还有问题,请分享一些截图,这样有助于理解。

    【讨论】:

    • 增加SizedBox 的高度,使生物输入字段位于屏幕底部。现在单击输入字段。现在键盘显示并重叠输入字段。我期望的是屏幕被调整大小并向下滚动,以便输入字段保持可见。
    猜你喜欢
    • 2021-05-07
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    • 2019-01-30
    • 1970-01-01
    • 2015-09-03
    相关资源
    最近更新 更多