English 中文(简体)
软盘键板把文字现场隐藏起来
原标题:Flutter Keyboard makes textfield hide

I m new to flutter. I ve added a form with a text field and when I clicked the textfield and keyboard comes, the textfield goes up.

This is my code :

Widget build(BuildContext context) {

MediaQueryData mediaQuery = MediaQuery.of(context);
return new Scaffold(
  body:  new Container(
      color: Colors.purple,
      constraints: new BoxConstraints.expand(),
      padding: EdgeInsets.only(top: 10.0,left: 10.0,right: 10.0, bottom: mediaQuery.viewInsets.bottom, ),
      child: SingleChildScrollView(
        child: Container(
            child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  SizedBox(height: 12.0),
                  Text(
                     What is your Business Name? ,
                    style: TextStyle(fontSize: 24.0),
                  ),
                  AppForm(),
                ],
              ),
            padding: EdgeInsets.only(left: 10.0,right: 10.0, bottom: mediaQuery.viewInsets.bottom),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(30.0)),
              color: Colors.white,
                ),
              )
          )
      ),
    );
  }

This is the result without opening the keyboard: Image without keyboard

This is the image after opening the keyboard: Image after opening the keyboard


这里是我 flu的博士产出。

Doctor summary (to see all details, run flutter doctor -v): [√] Flutter 
(Channel beta, v0.5.1, on Microsoft Windows [Version 10.0.17134.165], locale 
en-US) [√] Android toolchain - develop for Android devices (Android SDK 
28.0.0) [√] Android Studio (version 3.1) [!] VS Code, 64-bit edition (version 
1.25.1) [!] Connected devices ! No devices available ! Doctor found issues in 
2 categories.

any idea how to fix this?

最佳回答

我就是这样。 你们无疑在另一条手脚中打上了一fold。 在你们的冲碎 app中,即主要布局内,只应有一只手脚的植被。 简单地清除了你所拥有的所有祖先的耳光,只留下一只耳光。 尽管你能够在集装箱内打上一只手脚,但还是把一只手脚袋装入另一个耳光。

• 确保你的工作。 dart file 你没有这样做:

✖✖

return Scaffold(
body : YourNewFileName(),
);

Inspite of the above code do this:- ✔✔

return YourNewFileName();
问题回答
Scaffold(
    resizeToAvoidBottomInset: true,
    // ...
    appBar: AppBar(
      // ...
    ),
)

固定问题案文点被键盘隐藏

答案不是上述问题的具体内容,而是对那些仍然与主要委员会有问题的人,无论他们做什么,都可能有用。 我在试图解决这样一个问题的时候就去了这个页。

在问题发生之前,我一直在作一些改动,以尝试和改进我对开端的激烈检查。 根据某人的建议,我在以下几行中加入了:<代码><resources>< Format> section of the ways.xml file in the android/app/src/main/res/ Values rafter

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

This had the unexpected effect of stopping any fields scrolling up in the main app when the keyboard is displayed. This might be obvious to some, but it wasn t to me.

Hope this info helps someone.

你可以简单地把你想要永远不会被婚内的关键板藏起来的get子混为一谈,例如:

Padding(
         child: YourWidget()
         padding: EdgeInsets.only(
         bottom: MediaQuery.of(context).viewInsets.bottom)); 

resizeToAvoidBottomPadding is Deprecated use instead resizeToAvoidBottomInset: true

如果你使用ScreenUtilInit 一揽子计划,则可能制定<代码>InheritedMedia Query: real in the Constructionor of ScreenUtilInit。 它帮助我:

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

Removing above line from

android/app/src/main/res/ Values/ Formats.xml

made my app fixed to input field auto scroll upwards to come in view able on keyboards opens

页: 1

“enter

页: 1 页: 1 单一儿童法典

Scaffold(
body: SingleChildScrollView(
          reverse: true,
          child: Container()));

如果您使用<代码>Scaf /code>,则使用<代码>的包装。 单项子女/编码

页: 1 例如:

...
return Scaffold(
body: SingleChildScrollView(
    child: Column(
      children: <Widget>[
        TextField(),
        TextField(),
        TextField(),
      ],
    ),
  ),
);
...

this was really a lifesaver for me. Now the scaffold will become scrollable.

取消ToAaveBottomInset公司是缺席的。

return Scaffold(
      resizeToAvoidBottomInset: false,
   );

我把它定为不实之词,并做罚款。

考虑在文本领域使用剪辑

return Scaffold(
  appBar: AppBar(
    title: Text("Demo SoftKeyboard"),
  ),
  body: SingleChildScrollView(
    child: Column(
      children: [
          TextField(
            scrollPadding: EdgeInsets.only(bottom:40), // THIS SHOULD SOLVE YOUR PROBLEM
        ),                
      ],
    ),
  ),
);

我也面临这一问题。 我的解决办法是:

1/ Wrap the Column Widget (content of Dialog) within the Paids Widget with property patter:vantInsets. only(bottom): Media Query.of (context).viewInsets.bottom,

2/Wrap all widgets above within 单项子女/编码

下面是我的诊断书全文:

Future<T?> showDialogLikeBorrowBook<T>(
 BuildContext context, {
 bool barrierDismissible = true,
 required String labelDialog,
 required String labelMainButton,
 required Widget contentDialog,
 required Function() onTap,
 }) async {
       return await showGeneralDialog(
       context: context,
       barrierLabel: "barrierLabel",
       barrierDismissible: barrierDismissible,
       barrierColor: Colors.black.withOpacity(0.4),
       transitionDuration: const Duration(milliseconds: 300),
       transitionBuilder: (_, anim1, __, child) {
              return ScaleTransition(
              scale: Tween<double>(
              begin: 0.0,
              end: 1.0,
              ).animate(
                  CurvedAnimation(
                  parent: anim1,
                  curve: Curves.fastOutSlowIn,
                  ),
                 ),
            child: child,
          );
         },
    pageBuilder: (_, __, ___) {
       return Material(
       type: MaterialType.transparency,
       child: Align(
       alignment: Alignment.center,
       child: Padding(
       padding: EdgeInsets.symmetric(horizontal: R.dimens.mediumSpacing1)
            .copyWith(
          top: MediaQuery.of(context).viewPadding.top, // This attribute used to make sure the Dialog widget always show below the AppBar/StatusBar 
                                                       //if the Dialog widget has size with height large more normal size when the keyboard be shown
        ),
         child: GestureDetector(
           onTap: () {
            FocusScope.of(context).requestFocus(FocusNode()); // Wrap Dialog widget inside Gesture Detector to every time the user tap outside the TextField widget but still inside scope of Dialog widget,
                                                              //the FocusNode of TextField will be unfocus 
          },
           child: Container(
             constraints: const BoxConstraints(maxWidth: double.infinity),
             decoration: BoxDecoration(
               borderRadius:
                   BorderRadius.all(Radius.circular(R.dimens.smallRadius)),
               color: Colors.white,
             ),
            padding: EdgeInsets.all(R.dimens.mediumSpacing),
              child: _ShowContentDialog(
               labelDialog: labelDialog,
               labelMainButton: labelMainButton,
               contentDialog: contentDialog,
               onTap: onTap,
               ),
             ),
           ),
         ),
       ),
     );
   },
 );
}

class _ShowContentDialog extends StatelessWidget {
 const _ShowContentDialog();

@override
Widget build(BuildContext context) {
 return SingleChildScrollView(
   physics: BouncingScrollPhysics(),
   child: Padding(
     padding: EdgeInsets.only(
       bottom: MediaQuery.of(context).viewInsets.bottom, // This attribute will auto scale size of Column widget when the keyboard showed
     ),
     child: Column(
       mainAxisSize: MainAxisSize.min,
       children: [
           _renderLabelDialog(),
           ... something widget,
           CustomTextField(
              labelTextField: "Ghi chú",
              hintText: "Nhập ghi chú",
              textInputType: TextInputType.text,
              maxLines: 4,
              textController: _editNoteController,
             ),
           _renderButton(context),
           ],
         ),
       ),
     );
   }
 }

www.un.org/Depts/DGACM/index_spanish.htm 无键盘的诊断

“Dialog

Dialog with the keyboard when touch on the TextField widget

Dialog with the keyboard when touch on the TextField widget

在一片假肢中填满整个植被,然后在一只“儿童成长观察”中包含所有其他植被。

如果你的内容是可变的,但你没有像提到的其他答案一样使用手法,这就是我所用的解决办法。

SizedBox(height: (MediaQuery.of(context).viewInsets.bottom != 0) ? 200 : 16)

You can change the 200 and 16 value to some other convenient value as per your needs

Had the same problem today and using resizeToAvoidBottomInset: true and SingleChildScrollView solved my problem.

return Scaffold(
  appBar: AppBar(
    title: Text("TitleBar"),
  ),
  resizeToAvoidBottomInset: true,
  body: SingleChildScrollView(
    child: ... some widgets here...
    ,
  ),
);

我的固定点类似于格雷厄姆·德的答复。

我是利用一名家长宣布我自己的主题。 例如:

<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen">
    <item name="android:windowBackground">@android:color/white</item>
</style>

我先向“彩虹”小组提出了问题,因为应当能够使用一个完整的筛选主题,并具有正常的查塔图像。

I resolved the above issue by adding a Stack() as the body of my Scaffold(), this allows the TextField() object to slide up above the soft keyboard. Initially I used SingleChildScrollView() for the body which resulted in the TextField() objects being obscured by the soft keyboard.

为我工作的解决办法:

child: Scaffold(
          resizeToAvoidBottomInset: true,
          body: Stack(
            children: <Widget>[]

根据冲碎更新(2021年),“Reize ToAaveBottomInset:true”在关键板上出现一个黄色黑色地带错误。

This is how I fixed the above issue:

  1. Inside build() method, check if keyboard is open, bool keyboardIsOpen = MediaQuery.of(context).viewInsets.bottom != 0;
  2. Set resizeToAvoidBottomInset:true inside Scaffold
  3. Wrap your widget with a SizedBox() and set height like this: height: keyboardIsOpen ? MediaQuery.of(context).size.height * 0.2 : MediaQuery.of(context).size.width * 0.6,

在“彩虹”中,为了防止出现这一问题,我们可以做一件容易的工作。 我们必须将<代码>Text FieldsSingleChildScrollView作为在Schaf 夹中进行身体辩论的参照对象。 仅限使用<代码>SingleChildScrollView。 如果你不这样做,那不会奏效。 例如:

Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(
    title: Text("App"),
  ),
  body: SingleChildScrollView(
    child: Column(
      // mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: [
        Container(
          width: double.infinity,
          child: Card(
            color: Colors.blue,
            elevation: 5,
            child: Text()
          ),
        ),
        TextField(),
        TextField(),

      ],

Also, there is another way do this. In the above code, you can replace Column with ListView Widget like the below code:

Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(
    title: Text("App"),
  ),
  body: Container(
    height: 300,
    child: ListView(
      children: [
        Container(
          width: double.infinity,
          child: Card(
            color: Colors.blue,
            elevation: 5,
            child: Text(),
          ),
        ),
        TextField(),
        TextField(),

      ],

    

Here s a complete example which dynamically updates the padding:

“在关键板显示之前和之后”/

import  dart:ui ;
import  package:flutter/material.dart ;

class KeyboardPaddingTest extends StatefulWidget {
  const KeyboardPaddingTest({Key? key}) : super(key: key);

  @override
  _KeyboardPaddingTestState createState() => _KeyboardPaddingTestState();
}

class _KeyboardPaddingTestState extends State<KeyboardPaddingTest> {
  EdgeInsets _viewInsets = EdgeInsets.zero;
  SingletonFlutterWindow? window;
  final _textFieldController = TextEditingController();

  @override
  void initState() {
    super.initState();
    window = WidgetsBinding.instance?.window;
    window?.onMetricsChanged = () {
      setState(() {
        final window = this.window;
        if (window != null) {
          _viewInsets = EdgeInsets.fromWindowPadding(
            window.viewInsets,
            window.devicePixelRatio,
          ).add(EdgeInsets.fromWindowPadding(
            window.padding,
            window.devicePixelRatio,
          )) as EdgeInsets;
        }
      });
    };
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: double.infinity,
      color: Colors.greenAccent[100],
      alignment: Alignment.bottomCenter,
      child: Padding(
        padding: EdgeInsets.only(bottom: _viewInsets.bottom),
        child: Column(
          children: [
            Expanded(
              child: Center(
                child: Container(
                  width: 200.0,
                  color: Colors.lightBlueAccent[100],
                  child: TextField(
                    controller: _textFieldController,
                    decoration: const InputDecoration(
                      border: InputBorder.none,
                      hintText:  Tap to show keyboard ,
                    ),
                  ),
                ),
              ),
            ),
            const Text(
               Testing Keyboard ,
              style: TextStyle(
                fontSize: 24.0,
                fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

谨慎行事,不要将这两条线从安妮斯·曼尼费中删除。

android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"

我确实犯了这一错误,但我所有的“儿童成长”意见都没有奏效,而钥匙板正在抹去我所有形式的文本。

工作情况如下:

Scaffold(
    **resizeToAvoidBottomInset: true,**
    appBar: AppBar(
      // ...
    ),
)

值得注意的是,如果你在母子上有一只手脚或像“自动取款机”之类的任何手套,如果是这样的话,那么就把“ToAaveBottomInset:真实的,

如果主机的开放掩盖了文本现场,就是所有文本的最简单解决办法。


class LoginScreen extends StatelessWidget {
  const LoginScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Column(
        children: [
          Text("Login User"),
          SizedBox(
            height: 48,
          ),
          Focus(
            child: TextField(
              decoration: InputDecoration(hintText: "Enter your email"),
            ),
          )
        ],
      ),
    );
  }
} 


页: 1 它会更好地解决隐蔽的问题。

我有同样的问题,也使用了<代码>。 单身母亲 观点,但这种说法解决了我的问题。

我的问题在于这一法典中。

   Stack(
      childern:[
           SingleChildScrollView(),// In scollView i have textFeild when keyboard opens doneButton hide the textFeild.
           doneButtonWidget()//this button align with the bottom of the screen. 
   ]
)

解决这一问题,并解决了我的问题。

    Column(
       childern:[
            Expaned(  
                child:SingleChildScrollView(),// In scollView i have textFeild when keyboard opens doneButton hide the textFeild.
               flex:1
              ),
              doneButtonWidget()//this button align with the bottom of the screen. 
             ]
          )




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签