简体   繁体   English

Flutter:如何在 Flutter 中使 ListView 的高度 match_parent

[英]Flutter: How to make a ListView's height match_parent in Flutter

ListView's height should be as windows's height. ListView 的高度应该与窗口的高度相同。 So when keyboard opens, user can scroll down to see the widgets which covered by keyboard.因此,当键盘打开时,用户可以向下滚动以查看键盘覆盖的小部件。 And Widgets shouldn't change their position.并且小部件不应更改其 position。 I've used Align widget to position them, and wrapped with a Stack widget.我使用 Align 小部件到 position 它们,并用 Stack 小部件包装。 In other words: it should be exactly as Instagram login page.换句话说:它应该与 Instagram 登录页面完全一样。

I hope this helps: demo: https://i.ibb.co/g7C3K7K/dmeo.gif我希望这会有所帮助:演示: https://i.ibb.co/g7C3K7K/dmeo.gif

import 'package:flutter/material.dart';

class LoginPage extends StatefulWidget {
  @override
  _LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  final key = GlobalKey<ScaffoldState>();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: key,
      body: SingleChildScrollView(
        child: Container(
          height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Text(
                "Welcome to the login page",
                style: Theme.of(context).textTheme.display1,
              ),
              TextField(
                decoration: InputDecoration(hintText: "Name"),
              ),
              FlatButton(
                  onPressed: () {
                    key.currentState.showSnackBar(SnackBar(
                      content:
                          Text("I won't say your name but stay home, stay safe!"),
                    ));
                  },
                  child: Text("Say my name"))
            ],
          ),
        ),
      ),
    );
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android ListView高度为match_parent减去固定高度 - Android ListView height to match_parent minus fixed height Flutter,如何让子部件的高度与 SingleChildScrollView 中的父部件匹配? - Flutter,How to let a child widget's height match parent in SingleChildScrollView? match_parent不适用于SherlockFragment中listView的layout_height - match_parent not working for layout_height of listView in SherlockFragment 如何在Android中具有match_parent作为宽度和高度的列表视图下面有一个按钮 - How to have a button below a listview which has match_parent as width and height in android 如何使 Flutter ListView 高度与子高度相同(动态) - How to make Flutter ListView height same as children height(dynamic) Flutter 如何根据 ListView 的项目高度更改容器高度? - Flutter How to change container height based on the ListView's item height? Listview不会match_parent - Listview won't match_parent 如果ListView在NestedScrollView中,match_parent不适用于ListView - match_parent not working for ListView, if ListView is inside NestedScrollView 如何使 ListView 在颤动中可点击? - How to make ListView clickable in flutter? listview 项目文本未在 dialogframent kotlin 的 match_parent 中设置 - listview item text is not set in match_parent in dialogframent kotlin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM