【问题标题】:Flutter keyboard overlapping with resizeToAvoidBottomPadding颤振键盘与 resizeToAvoidBottomPadding 重叠
【发布时间】:2019-08-10 17:07:16
【问题描述】:

我有一个带有 DefaultTabController 的页面:

 @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        resizeToAvoidBottomPadding: true,
        appBar: AppBar(
            bottom: TabBar(
              indicatorColor: Colors.red,
              indicator: BoxDecoration(
                color: buttonColor,
              ),
              tabs: [Tab(text: "Login"), Tab(text: "Register", key: Key("tabRegistro"))],
            ),
            centerTitle: true,
            title: Text(appBarTitle)),
        body: TabBarView(
          children: [
            new LoginPage(),
            new RegisterPage(),
          ],
        ),
      ),
    );
  }

例如,LoginPage 构建是:

@override
  Widget build(BuildContext context) {
    return Scaffold(
        resizeToAvoidBottomPadding: true,
        key: _scaffoldKey,
        body: SingleChildScrollView(
            child: GestureDetector(
          onTap: () {
            FocusScope.of(context).unfocus();
          },
          child: Center(
            child: Container(
              color: backgroundColor,
              child: Padding(
                  padding: const EdgeInsets.all(36.0),
                  child: Form(
                    key: formKey,
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: <Widget>[
                        SizedBox(
                          height: 155.0,
                          child: Image.asset(
                            "assets/images/pet.PNG",
                            fit: BoxFit.contain,
                          ),
                        ),
                        SizedBox(height: 20.0),
                        emailField,
                        SizedBox(height: 10.0),
                        passwordField,
                        SizedBox(height: 20.0),
                        loginButon,
                        SizedBox(height: 20.0),
                        GoogleSignInButton(
                            darkMode: true,
                            text: "Login with Google",
                            onPressed: () {
                              _sigIn();
                            }),
                      ],
                    ),
                  )),
            ),
          ),
        )));
      }

但是当我写作时,键盘覆盖了文本字段并且它们是不可见的。

SingleChildScrollView 在它工作之前,但现在它不能正常工作。我曾尝试输入resizeToAvoidBottomPadding: true,但它不起作用。我能做些什么来解决这个问题?

【问题讨论】:

  • FocusScope.of(context).unfocus();这条线是什么意思。它显示错误,如果我删除它,它对我来说很好。
  • 这一行是为了隐藏键盘。

标签: flutter dart flutter-layout


【解决方案1】:

代码没问题,问题出在 Android.manifest.xml。我正在使用 Android Simulator 并隐藏状态栏我把这些行:

android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"

如果我把原来的行它工作。原行是:

android:theme="@style/LaunchTheme"

【讨论】:

    猜你喜欢
    • 2019-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多