简体   繁体   English

如何使用 ListView / Flutter 使我的屏幕可滚动

[英]How to make my Screen Scrollable with ListView / Flutter

i cant seem to work my way around this i cant make it scrollable tried all the solution but i am getting errors in every method so decided to post my code here and hope someone will report the code with listview scrollable page same code the current error i am getting is this:我似乎无法解决这个问题我无法使其可滚动尝试了所有解决方案但我在每种方法中都遇到错误所以决定在此处发布我的代码并希望有人将使用 listview 可滚动页面的代码报告与当前错误相同的代码我我得到的是:

Exception caught by rendering library ═════════════════════════════════ Null check operator used on a null value The relevant error-causing widget was ListView lib\\signup.dart:17 ════════════════════════════════════════════════════════════════════════════════ ════════ Exception caught by rendering library ═════════════════════════════════ Null check operator used on a null value The relevant error-causing widget was ListView渲染库捕获的异常============================== 在空值上使用的空检查运算符相关错误-导致widget为ListView lib\\signup.dart:17 =================================== ================================================ 例外被渲染库捕获=============================== 对空值使用的空检查运算符相关的错误原因小部件是 ListView

import 'package:flutter/material.dart';
import 'package:property_records/constraint.dart';

class Signup extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: SizedBox(
        height: 200.0,
        child: ListView(
          children: <Widget>[
            Expanded(
              child: Container(
                decoration: BoxDecoration(
                  image: DecorationImage(
                    image: AssetImage('assets/images/pr.png'),
                  ),
                ),
              ),
            ),
            Expanded(
              child: Padding(
                padding: const EdgeInsets.symmetric(horizontal: 20),
                child: Column(
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          "Register Now",
                          style: Theme.of(context).textTheme.headline5.copyWith(fontWeight: FontWeight.bold),
                        ),
                      ],
                    ),
                    Row(
                      children: [
                        Padding(
                          padding: const EdgeInsets.only(right: 5),
                          child: Icon(
                            Icons.lock,
                            color: KPrimaryColor,
                          ),
                        ),
                        Expanded(
                          child: TextField(decoration: InputDecoration(hintText: "Your Name")),
                        )
                      ],
                    ),
                    Row(
                      children: [
                        Padding(
                          padding: const EdgeInsets.only(right: 5),
                          child: Icon(
                            Icons.email,
                            color: KPrimaryColor,
                          ),
                        ),
                        Expanded(
                          child: TextField(decoration: InputDecoration(hintText: "Email Address")),
                        )
                      ],
                    ),
                    Row(
                      children: [
                        Padding(
                          padding: const EdgeInsets.only(right: 5),
                          child: Icon(
                            Icons.lock,
                            color: KPrimaryColor,
                          ),
                        ),
                        Expanded(
                          child: TextField(decoration: InputDecoration(hintText: "Password")),
                        )
                      ],
                    ),
                    Row(
                      children: [
                        Padding(
                          padding: const EdgeInsets.only(right: 5),
                          child: Icon(
                            Icons.lock,
                            color: KPrimaryColor,
                          ),
                        ),
                        Expanded(
                          child: TextField(decoration: InputDecoration(hintText: "Confirm Password")),
                        )
                      ],
                    ),
                    Row(
                      children: [
                        Padding(
                          padding: const EdgeInsets.only(right: 5),
                          child: Icon(
                            Icons.lock,
                            color: KPrimaryColor,
                          ),
                        ),
                        Expanded(
                          child: TextField(decoration: InputDecoration(hintText: "Mobile Number")),
                        )
                      ],
                    ),
                    Row(
                      children: [
                        Padding(
                          padding: const EdgeInsets.only(right: 5),
                          child: Icon(
                            Icons.lock,
                            color: KPrimaryColor,
                          ),
                        ),
                        Expanded(
                          child: TextField(decoration: InputDecoration(hintText: "Office Name")),
                        )
                      ],
                    ),
                    Spacer(),
                    FittedBox(
                      child: Padding(
                        padding: const EdgeInsets.only(bottom: 150),
                        child: Container(
                          padding: EdgeInsets.symmetric(horizontal: 36, vertical: 16),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(30),
                            color: KPrimaryColor,
                          ),
                          child: Row(
                            children: [
                              Text(
                                "Sign Up",
                                style: TextStyle(
                                  fontWeight: FontWeight.bold,
                                  color: Colors.white,
                                ),
                              ),
                              Icon(
                                Icons.arrow_forward,
                                color: Colors.white,
                              )
                            ],
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

You can wrap everything into a SingleChildScrollView你可以把所有东西都包装成一个SingleChildScrollView

SingleChildScrollView(
  child: MyBigMessedView(),
)

Just make sure, that you have phyics: NeverScrollableScrollPhysics() in your nested ListView if you have some.只要确保你有phyics: NeverScrollableScrollPhysics()在你的嵌套ListView如果你有的话。

Also, don't use Expanded as every parent widget.另外,不要将 Expanded 用作每个父小部件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM