颤动的底部溢出n个像素,并且列的末端对齐

时间:2020-03-25 20:51:47

标签: flutter flutter-layout

我试图在Flutter中显示一个简单的注册屏幕,但是显示键盘时出现bottom overflowed by n pixels错误。

我的Flutter小部件:

class SignUpScreen extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Padding(
            padding: const EdgeInsets.all(16),
            child: SafeArea(
                child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    mainAxisAlignment: MainAxisAlignment.end,
                    mainAxisSize: MainAxisSize.max,
                    children: [
                      Text(S
                          .of(context)
                          .signUpTitle,
                          style: AppTextTheme.kBigTitle),
                      Container(height: 16),
                      Text(
                          "Some text describing what happens when we do stuff with things and other stuff that probably won't fit in this layout and will give us the horrible error banner ath the bottom of the screen. There's scope for even more text depending on how I'm feeling this evening. It could be that I stop typing, it could be that I type more and more. It really depends on what ",
                          style: AppTextTheme.kParagraph),
                      Container(height: 24),
                      Text("Email address"),
                      TextField(
                          decoration: InputDecoration(
                              hintText: "Email address")),
                      Container(height: 8),
                      Text("Password"),
                      TextField(
                          decoration: InputDecoration(hintText: "Password")),
                      Container(height: 24),
                      MaterialButton(
                        onPressed: () {
                          // Do stuff
                        },
                        child: Text("Sign up"),
                      ),
                      Container(height: 32),
                      FlatButton(
                        child: Column(
                          children: [
                            Text(
                              "Some other text",
                              style: AppTextTheme.kParagraphBold,
                            ),
                            Text("Sign in instead",
                                style: AppTextTheme.kParagraphBold.copyWith(
                                    decoration: TextDecoration.underline)),
                          ],
                        ),
                        onPressed: () {
                          Navigator.pushReplacementNamed(
                              context, RoutePaths.SIGN_IN);
                        },
                      )
                    ]))));
  }
}

我已经看过各种解决方案,但是每个解决方案都有不希望的折衷,这会破坏设计或带来不希望的用户体验:

  • Column包裹在SingleChildScrollView中意味着Textfield被隐藏。当键盘出现时。
  • resizeToAvoidBottomInset: false上设置Scaffold也会使TextField隐藏在键盘后面。
  • Column替换为ListView意味着我无法将mainAxisAlignment设置为MainAxisAlignment.end来获得屏幕快照,其中包含内容底部对齐。

问题:

如何在内容朝着屏幕底部对齐的同时实现我想要的UI,并且在用户键入而没有像素溢出错误时仍然能够看到TextField

Screenshot of the desired outcome

1 个答案:

答案 0 :(得分:1)

我刚刚通过用client.once('ready', () => { //Start TENSORFLOW tests const model = tf.sequential(); model.add(tf.layers.dense({ units: 1, inputShape: [200] })); model.compile({ loss: 'meanSquaredError', optimizer: 'sgd', metrics: ['MAE'] }); // Generate some random fake data for demo purpose. const xs = tf.randomUniform([10000, 200]); const ys = tf.randomUniform([10000, 1]); const valXs = tf.randomUniform([1000, 200]); const valYs = tf.randomUniform([1000, 1]); // Start model training process. async function train() { await model.fit(xs, ys, { epochs: 100, validationData: [valXs, valYs], // Add the tensorBoard callback here. callbacks: tf.node.tensorBoard('/tmp/fit_logs_1') }); } train(); //End TENSORFLOW tests console.log('Ready!'); console.log("Servers:") client.guilds.cache.map((guild) => { console.log(" - " + guild.name) // List all channels client.guilds.cache.map((channel) => { console.log(` -- ${channel.name} (${channel.type}) - ${channel.id}`) }); }); }); Container包装列窗口小部件来获得UI来解决它。希望对您有帮助。

SingleChildScrollview