首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Flutter RenderFlex子项具有非零弯曲,但传入的高度约束是无界的。134像素的错误?

Flutter RenderFlex子项具有非零弯曲,但传入的高度约束是无界的。134像素的错误?
EN

Stack Overflow用户
提问于 2020-11-28 09:04:15
回答 1查看 137关注 0票数 1

这是我在android studio(Windows系统)中的代码。

如何解决这个问题,我已经使用了单一的滚动视图,但得到的RenderFlex孩子有非零

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
error......? 

另外,我已经用小工具包装,但同样的问题......?

下面是我的代码:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
     void main() {
              runApp(MyApp());
            }
            class MyApp extends StatelessWidget {
              // This widget is the root of your application.
              @override
              Widget build(BuildContext context) {
                return MaterialApp(
                  debugShowCheckedModeBanner: false,
                  theme: ThemeData(
                    fontFamily: 'ubuntu',
                  ),
                  home: MyHomePage(),
                  routes: {
                    '/MainPage' : (context)=>MainPage(),
                  },
                );
              }
            }
            class MyHomePage extends StatefulWidget {
              @override
              _MyHomePageState createState() => _MyHomePageState();
            }
            
            class _MyHomePageState extends State<MyHomePage> {
              @override
              Widget build(BuildContext context) {
                return Scaffold(
                  resizeToAvoidBottomInset: false,
                  backgroundColor: purple,
                  body: SingleChildScrollView(
                    child: Column(
                      children: [
                        Container(
                          width: 100,
                          height: 50,
                          margin: EdgeInsets.only(top: 40),
                          decoration: BoxDecoration(
                              image: DecorationImage(
                                  image: AssetImage('asset/image/logo.png')
                              )
                          ),
                        ),
                        SizedBox(height: 30,),
                        Text("Clean Home\nClean Life", style: TextStyle(
                            fontSize: 40,
                            color: Colors.white,
                            fontWeight: FontWeight.w900
                        ),textAlign: TextAlign.center,),
                        SizedBox(height: 30,),
                        Text("Book Cleans At The Comfort \nOf Your Home", style: TextStyle(
                          fontSize: 18,
                          color: Colors.white,
                          fontWeight: FontWeight.w400,
            
                        ), textAlign: TextAlign.center,),
                        SizedBox(height: 60,),
                        Container(
                          height: 350,
                          width: MediaQuery.of(context).size.width,
                          decoration: BoxDecoration(
                              image: DecorationImage(
                                  image: AssetImage('asset/image/splash.png'),
                                  fit: BoxFit.cover
                              )
                          ),
                        ),
                        Expanded(
                          child: Container(),
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.end,
                          children: [
                            InkWell(
                              onTap: openMainPage,
                              child: Container(
                                padding: EdgeInsets.symmetric(horizontal: 60, vertical: 30),
                                decoration: BoxDecoration(
                                    borderRadius: BorderRadius.only(topLeft: Radius.circular(20)),
                                    color: Colors.white
                                ),
                                child: Text('Continue..', style: TextStyle(
                                    fontSize: 17,
                                    fontWeight: FontWeight.w600,
                                    color: purple
                                ),),
                              ),
                            )
                          ],
                        )
                      ],
                    ),
                  ),
                );
              }
            
              void openMainPage()
              {
                Navigator.pushNamed(context, '/MainPage');
              }
            }
........
EN

回答 1

Stack Overflow用户

发布于 2020-11-28 11:12:31

要使内容可滚动,它必须溢出视口高度。由于您在使用Row之前使用Expanded,因此您的Column将扩展到最大高度,并且不会有任何滚动。如果您从Container中删除Expanded并设置Container高度(例如500.0),那么您的内容将溢出视口并变为可滚动。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        fontFamily: 'ubuntu',
      ),
      home: MyHomePage(),
      // routes: {
      //   '/MainPage' : (context)=>MainPage(),
      // },
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      backgroundColor: Colors.purple,
      body: SingleChildScrollView(
        child: Column(
          children: [
            Container(
              width: 100,
              height: 50,
              margin: EdgeInsets.only(top: 40),
              decoration: BoxDecoration(
                  image: DecorationImage(
                      image: NetworkImage(
                          'https://2.bp.blogspot.com/-3VnKmSv5FXg/XCc1YFehs-I/AAAAAAAAPt4/zxnpIVoYSvQFGtIVeNqTILDsCaIg8Ql-wCLcBGAs/s1600/Mirillis%2B-%2BSplash%2BPremium%2BFull%2Bversion.png'))),
            ),
            SizedBox(
              height: 30,
            ),
            Text(
              "Clean Home\nClean Life",
              style: TextStyle(
                  fontSize: 40,
                  color: Colors.white,
                  fontWeight: FontWeight.w900),
              textAlign: TextAlign.center,
            ),
            SizedBox(
              height: 30,
            ),
            Text(
              "Book Cleans At The Comfort \nOf Your Home",
              style: TextStyle(
                fontSize: 18,
                color: Colors.white,
                fontWeight: FontWeight.w400,
              ),
              textAlign: TextAlign.center,
            ),
            SizedBox(
              height: 60,
            ),
            Container(
              height: 350,
              width: MediaQuery.of(context).size.width,
              decoration: BoxDecoration(
                  image: DecorationImage(
                      image: NetworkImage(
                          'https://2.bp.blogspot.com/-3VnKmSv5FXg/XCc1YFehs-I/AAAAAAAAPt4/zxnpIVoYSvQFGtIVeNqTILDsCaIg8Ql-wCLcBGAs/s1600/Mirillis%2B-%2BSplash%2BPremium%2BFull%2Bversion.png'),
                      fit: BoxFit.cover)),
            ),
            //! Comment this
            // Expanded(
            //   child: Container(),
            // ),
            //! Add height here
            Container(
              height: 500,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                InkWell(
                  onTap: openMainPage,
                  child: Container(
                    padding: EdgeInsets.symmetric(horizontal: 60, vertical: 30),
                    decoration: BoxDecoration(
                        borderRadius:
                            BorderRadius.only(topLeft: Radius.circular(20)),
                        color: Colors.white),
                    child: Text(
                      'Continue..',
                      style: TextStyle(
                          fontSize: 17,
                          fontWeight: FontWeight.w600,
                          color: Colors.purple),
                    ),
                  ),
                )
              ],
            )
          ],
        ),
      ),
    );
  }

  void openMainPage() {
    Navigator.pushNamed(context, '/MainPage');
  }
}

另外,我用NetworkImage替换了AssetImage,因为我没有你的图片。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65047993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文