When the keyboard appears, the Flutter widgets resize. How to prevent this?

后端 未结 9 1230
灰色年华
灰色年华 2020-12-02 05:51

I have a Column of Expanded widgets like this:

 return new Container(
      child: new Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
               


        
相关标签:
9条回答
  • 2020-12-02 06:24

    Well I think if we implement @Aman's solution it will make our app behaves ugly as when the keyboard appears, it will not adjust our viewport of the screen as per available height and it will make out other fields hide behind the keyboard. So I would suggest useSingleChildScrollView instead.

    Wrap your code with SingleChildScrollView as given below,

     return new Container(
      child: SingleChildScrollView(
        child: new Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          new Expanded(
            flex: 1,
            child: convertFrom,
          ),
          new Expanded(
            flex: 1,
            child: convertTo,
          ),
          new Expanded(
            flex: 1,
            child: description,
          ),
        ],
      ),
     ),
    );
    
    0 讨论(0)
  • 2020-12-02 06:27

    Method 1: Remove android:windowSoftInputMode="adjustResize" from AndroidManifest.xml file (Otherwise it will override flutter code) and add resizeToAvoidBottomPadding: false in Scaffold like below:

    Scaffold(
          resizeToAvoidBottomPadding: false,
          appBar: AppBar()
    )
    

    Method 2(Not Recommended): Just Add android:windowSoftInputMode="stateVisible" in android AndroidManifest.xml in activity it will only work for Android an Not for IOS like.

    <activity
           ...
            android:windowSoftInputMode="stateVisible">
    

    Note: Don't set it to android:windowSoftInputMode="adjustResize"

    0 讨论(0)
  • 2020-12-02 06:29

    In your Scaffold, set resizeToAvoidBottomInset property to false.

    Property "resizeToAvoidBottomPadding" is deprecated now.... In your Scaffold, set resizeToAvoidBottomPadding property to false.

    0 讨论(0)
  • 2020-12-02 06:34

    Set resizeToAvoidBottomInset to false instead of resizeToAvoidBottomPadding which is deprecated.

        return Scaffold(
          resizeToAvoidBottomInset : false,
          body: YourWidgets(),
        );
    
    0 讨论(0)
  • 2020-12-02 06:36

    For me changing below item property from true to false

    <item name="android:windowFullscreen">false</item>
    

    in file

    android/app/src/main/res/values/styles.xml
    

    has made Flutter drag all page content upwards on input focus

    0 讨论(0)
  • 2020-12-02 06:41

    Depending on the use case you could also consider using a listview. That would ensure that the contents scroll when there is not enough room. As an example, you can look at the textfield demo in the gallery app

    0 讨论(0)
提交回复
热议问题