PageView 未显示在 SingleChildScrollView 中

PageView not showing inside SingleChildScrollView

我使用 PageView 创建了 ViewPager 但是当我把它放在 SingleChildScrollView 里面时它停止了 showing.However 当我把它放在 SingleChildScrollView 外面时它显示 fine.How 要在 SingleChildScrollView 里面显示 PageView?

Expanded(
          flex: 8,
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min,
              children: [

                Card(
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(5.0),
                    ),
                    margin: const EdgeInsets.fromLTRB(8.0, 16.0, 8.0, 0),
                    child: Padding(
                        padding:
                            const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 8.0),
                        child: promoPager())),
              ],
            ),
          ),
        )
Widget promoPager() {
    final PageController controller = PageController();
    return Stack(
      children: [
        PageView(
            controller: controller,
            onPageChanged: (int page) {
              setState(() {
                tabController?.index = page;
              });
            },
            children: const [
              Image(
                  image: AssetImage('assets/dubai.jpg'), fit: BoxFit.fill),
              Image(
                  image: AssetImage('assets/webcheckin.jpg'),
                  fit: BoxFit.fill),
              Image(
                  image: AssetImage('assets/maldives.gif'),
                  fit: BoxFit.fill),
              Image(
                  image: AssetImage('assets/giraffe.jpg'), fit: BoxFit.fill)
            ]),
        Positioned(
            bottom: 5,
            right: 5,
            child: TabPageSelector(
                controller: tabController,
                selectedColor: const Color(0xffea2330)))
      ],
    );

我的小部件树:- SinglechildScrollView->Column->Card->Padding->Stack->pageview

PageView 提供高度解决了这个问题。您可以使用 SizedBox(height:x)AspectRatio 并在此处使用图像纵横比。

更多关于PageView and AspectRatio