首页 > 解决方案 > 堆栈小部件在 SCSV、颤振中不滚动

问题描述

我在小部件之上使用一对一小Stack部件,但我遇到的问题是我的整个 Stack 小部件无法滚动以查看全部内容。我用a 包裹了小部件,但问题仍然存在。如果我用 a 包装 Stack 小部件并使其可滚动,但我仍然看不到页面的全部内容。我的错误在哪里,这就是我想知道的?我应该用什么小部件来包装 Stack 还是有更好的方法来解决我的问题?简而言之,我将 a 堆叠在 an 之上,并且我需要整个小部件是可滚动的,这样我才能看到 Stack 小部件的全部内容。这是代码:PositionedImage.assetStackSingleChildScrollViewContainter height: MediaQuery.of(context).size.height,ColumnImageStack

Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey,
      body: SafeArea(
        child: SingleChildScrollView(
          child: Stack(
            overflow: Overflow.visible,
            children: [
              Image.asset(
                'lib/modules/common/images/logo.png',
                width: double.infinity,
                height: 196.0,
              ),
              Positioned(
                width: MediaQuery.of(context).size.width,
                height: MediaQuery.of(context).size.height,
                top: 136.0,
                child: Column(
                  children: [
                    Container(), // some content inside the container
                    Container(), // // some content inside the container
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

在此先感谢您的帮助!

标签: fluttermobileflutter-layout

解决方案


如果你的意思是在背面有一个图像和可滚动的内容,请检查这个答案,如果不是让我知道并分享你想要的原型/图像。



  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey,
      body: SafeArea(
        child: SingleChildScrollView(
          child: SizedBox(
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height * 3,
            child: Stack(
              fit: StackFit.loose,
              children: [
                Align(
                  alignment: Alignment.topCenter,
                  child: Image.asset(
                    'assets/image.jpg',
                    width: double.infinity,
                    height: 196.0,
                  ),
                ),
                Positioned(
                  top: 136.0,
                  child: SizedBox(
                    width: MediaQuery.of(context).size.width,
                    height: MediaQuery.of(context).size.height,
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: List.generate(
                        2,
                        (index) => Container(
                          height: 100,
                          width: double.infinity,
                          color: index % 2 == 0
                              ? Colors.amberAccent
                              : Colors.cyanAccent,
                        ), // some content inside the container
                        // some content inside the container
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

推荐阅读