拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 页面视图未显示在SingleChildScrollView中

页面视图未显示在SingleChildScrollView中

白鹭 - 2022-02-22 1963 0 0

我使用 PageView 创建了 ViewPager,但是当我将它放在 SingleChildScrollView 中时它停止显示。但是,当我将它放在 SingleChildScrollView 之外时,它显示正常。如何在 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

uj5u.com热心网友回复:

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

有关PageViewAspectRatio 的更多信息

标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *