键盘将输入字段隐藏在颤动中

时间:2020-06-11 10:10:19

标签: flutter

我看到这个问题已经问了很多遍了,但是没有一个解决方案对我有用。在下面的代码中,单击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">

有人知道会有什么不同吗?

1 个答案:

答案 0 :(得分:0)

我已经尝试过此代码,并且可以正常工作。

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,
                ),]))));

如果仍然有问题,请分享一些屏幕截图,这样对理解会有所帮助。

相关问题