当我水平翻转屏幕时,我希望有人能帮助我解决溢出问题.当我水平翻转屏幕时,我得到一个异常:

溢出的RenderFlex具有轴的方向.竖的

和我的模拟器上的提示符:

底部溢出194像素

现在由于这个异常,我try 添加一个"SingleChildScrollView"来解决这个问题,允许答案选项滚动并且不会溢出,但是滚动似乎不起作用,问题仍然存在.所以我希望有人能帮我解决这个问题,让我的测验页面也能水平运行而不会出错.非常感谢您的帮助!

quiz.dart

class Salvation extends StatefulWidget {
  const Salvation({Key? key}) : super(key: key);

  @override
  State<Salvation> createState() => _SalvationState();
}

class _SalvationState extends State<Salvation> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Quiz')),
      body: LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints) {
          return Column( children: [
              Container(
                height: constraints.maxHeight / 4,
                child: Padding(padding: EdgeInsets.fromLTRB(12, 12, 12, 8),
                child: Align(
                  alignment: Alignment.topLeft,
                  child: Text('Question',
                      style: TextStyle(fontSize: 20.0,)),))
              ),
              Visibility(// visible: ,
                child: Container(
                height: constraints.maxHeight / 4,
                child: Padding(padding: EdgeInsets.fromLTRB(12, 3, 12, 6),
                  child: Container(
                      decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10),
                      color: Color.fromRGBO(118, 60, 51, 0.5),
                    ),
                    width: double.infinity,
                    child: Padding(padding: EdgeInsets.fromLTRB(12, 8, 12, 8), 
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                      Text('Example/Image Box',
                      style: TextStyle(fontSize: 17.0,)),
                      // RichText(text: text)
                      Text('Hello there',
                      style: TextStyle(fontSize: 15.0,)),
                    ],),
                  )),
                ),
              ),),
              SingleChildScrollView( 
                child:Container(
                height: constraints.maxHeight / 2,
                color: const Color.fromRGBO(155, 205, 255, 0.8),
                child: Padding(padding: const EdgeInsets.fromLTRB(12, 12, 12, 20),
                  child: Column(children: [
                    Padding(padding: EdgeInsets.fromLTRB(0, 0, 0, 6),
                    child: ListTile(
                      title: Text('Option A'),
                      tileColor: const Color.fromRGBO(6, 145, 248, 1),
                      shape: RoundedRectangleBorder(
                        side: const BorderSide(color: Colors.black, width: 10),
                        borderRadius: BorderRadius.circular(5)),
                      onTap: () {},
                    ),),
                    Padding(padding: EdgeInsets.fromLTRB(0, 0, 0, 6),
                    child: ListTile(
                      title: Text('Option B'),
                      tileColor: const Color.fromRGBO(6, 145, 248, 1),
                      shape: RoundedRectangleBorder(
                        side: const BorderSide(color: Colors.black, width: 10),
                        borderRadius: BorderRadius.circular(5)),
                      onTap: () {},
                    ),),
                    Padding(padding: EdgeInsets.fromLTRB(0, 0, 0, 6),
                    child: ListTile(
                      title: Text('Option C'),
                      tileColor: const Color.fromRGBO(6, 145, 248, 1),
                      shape: RoundedRectangleBorder(
                        side: const BorderSide(color: Colors.black, width: 10),
                        borderRadius: BorderRadius.circular(5)),
                      onTap: () {},
                      onLongPress: () {},
                    ),),
                    Padding(padding: EdgeInsets.fromLTRB(0, 0, 0, 6),
                    child: ListTile(
                      title: Text('Option D'),
                      tileColor: const Color.fromRGBO(6, 145, 248, 1),
                      shape: RoundedRectangleBorder(
                        side: const BorderSide(color: Colors.black, width: 10),
                        borderRadius: BorderRadius.circular(5)),
                      onTap: () {},
                    ),),

                  ]),
                ),
              ),
              )],
          );
        },
      ),
    );
  }
}

编辑:此问题已得到回答,但解决方案产生了另一个问题.所以,如果你想帮助解决this question个问题,或者你遇到了同样的问题,请点击链接.:)

推荐答案

您不需要在singlechildscllview中换行列,而不需要容器.

class Salvation extends StatefulWidget {
  const Salvation({Key? key}) : super(key: key);

  @override
  State<Salvation> createState() => _SalvationState();
}

class _SalvationState extends State<Salvation> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Quiz')),
      body: LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints) {
          return Column(
            children: [
              Container(
                  height: constraints.maxHeight / 4,
                  child: Padding(
                      padding: EdgeInsets.fromLTRB(12, 12, 12, 8),
                      child: Align(
                        alignment: Alignment.topLeft,
                        child: Text('Question',
                            style: TextStyle(
                              fontSize: 20.0,
                            )),
                      ))),
              Visibility(
                // visible: ,
                child: Container(
                  height: constraints.maxHeight / 4,
                  child: Padding(
                    padding: EdgeInsets.fromLTRB(12, 3, 12, 6),
                    child: Container(
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(10),
                          color: Color.fromRGBO(118, 60, 51, 0.5),
                        ),
                        width: double.infinity,
                        child: Padding(
                          padding: EdgeInsets.fromLTRB(12, 8, 12, 8),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text('Example/Image Box',
                                  style: TextStyle(
                                    fontSize: 17.0,
                                  )),
                              // RichText(text: text)
                              Text('Hello there',
                                  style: TextStyle(
                                    fontSize: 15.0,
                                  )),
                            ],
                          ),
                        )),
                  ),
                ),
              ),
//not here
              Container(
               height: constraints.maxHeight/2,
                color: const Color.fromRGBO(155, 205, 255, 0.8),
                child: Padding(
                  padding: const EdgeInsets.fromLTRB(12, 12, 12, 20),
                  child: SingleChildScrollView(                 //here
                    child: Column(children: [
                      Padding(
                        padding: EdgeInsets.fromLTRB(0, 0, 0, 6),
                        child: ListTile(
                          title: Text('Option A'),
                          tileColor: const Color.fromRGBO(6, 145, 248, 1),
                          shape: RoundedRectangleBorder(
                              side: const BorderSide(
                                  color: Colors.black, width: 10),
                              borderRadius: BorderRadius.circular(5)),
                          onTap: () {},
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.fromLTRB(0, 0, 0, 6),
                        child: ListTile(
                          title: Text('Option B'),
                          tileColor: const Color.fromRGBO(6, 145, 248, 1),
                          shape: RoundedRectangleBorder(
                              side: const BorderSide(
                                  color: Colors.black, width: 10),
                              borderRadius: BorderRadius.circular(5)),
                          onTap: () {},
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.fromLTRB(0, 0, 0, 6),
                        child: ListTile(
                          title: Text('Option C'),
                          tileColor: const Color.fromRGBO(6, 145, 248, 1),
                          shape: RoundedRectangleBorder(
                              side: const BorderSide(
                                  color: Colors.black, width: 10),
                              borderRadius: BorderRadius.circular(5)),
                          onTap: () {},
                          onLongPress: () {},
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.fromLTRB(0, 0, 0, 6),
                        child: ListTile(
                          title: Text('Option D'),
                          tileColor: const Color.fromRGBO(6, 145, 248, 1),
                          shape: RoundedRectangleBorder(
                              side: const BorderSide(
                                  color: Colors.black, width: 10),
                              borderRadius: BorderRadius.circular(5)),
                          onTap: () {},
                        ),
                      ),
                    ]),
                  ),
                ),
              )
            ],
          );
        },
      ),
    );
  }
}

Flutter相关问答推荐

手势捕获的异常:类型';Double';不是类型转换中类型';Double';的子类型

当键盘在抖动中打开时,如何才能看到包装在SingleChildScrollView中的列中的最后一个小工具?

什么是dart :这只是dart ?

为什么PUT方法没有发出任何响应?

当我转到其他屏幕并按下后退按钮时,屏幕将不会刷新

按一下按钮即可更新 fl_chart

Flutter:我的应用程序是否需要包含退款购买?

如何从flutter中不同类别的列表中获取所有产品

「Flutter」错误:没有名为'kind'的命名参数

Flutter居中的SizedBox无法居中

为什么我们需要使用ChangeNotifierProvider而不是仅仅使用ChangeNotifier?

这是使用导航功能处理从一页到另一页的移动的最佳方式

如何在 flutter 的alert 对话框中实现进度指示器?

Pub get 尚未运行

在 Flutter 中更改高架按钮 OnPressed 的背景 colored颜色

如何在 flutter 中过滤 DateTime(intl)?

使用 onPressed 切换到另一个屏幕无法正常工作

CircleAvatar 在 ListTile 中领先

构建失败 - 无法解析 io.grpc:grpc-core:[1.28.0]. (是的,我已经升级到 mavenCentral())

既然我们已经有了 Flutter 的内置 setState,为什么还要在 Flutter 中使用 BloC 或 Provider?