繁体   English   中英

在扩展小部件 flutter 的自己的容器中滚动,我怎样才能让它滚动整个页面? ( Flutter )

[英]Scrolling in its own container in expanded widget flutter, How can i make it scroll through the whole page ? ( Flutter )

包装在扩展小部件内的 ProductModel class 正在其自己的容器中滚动,我怎样才能让它滚动整个页面。 ..................................................... ..................................................... ..................................................... ..................................................

在此处输入图像描述

主页 class

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

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  @override
  Widget build(BuildContext context) {
    int _current;
    return Scaffold(
      appBar: AppBar(
        actions: [
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Icon(
              Icons.notifications_active,
              color: Mythemes.darkbluishcolor,
            ),
          )
        ],
      ),
      drawer: MyDrawer(),
      body: SafeArea(
        child: SingleChildScrollView(
          child: Container(
            color: Mythemes.creamcolor,
            height: MediaQuery.of(context).size.height,
            child: (CatalogModel.items != null && CatalogModel.items.isNotEmpty)
                ? Padding(
                    padding: const EdgeInsets.all(14.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        PageHeader(),
                        Expanded(
                          child: SpecialPrice(),
                          flex: 2,
                        ),
                        Padding(
                          padding: const EdgeInsets.fromLTRB(8, 12, 8, 2),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                "Popular Brands",
                                style: TextStyle(
                                  fontSize: 18,
                                  fontWeight: FontWeight.w500,
                                  color: Mythemes.darkbluishcolor,
                                ),
                              ),
                              Text(
                                "See all",
                                style: TextStyle(
                                  fontSize: 15,
                                  fontWeight: FontWeight.w500,
                                  color: Colors.black54,
                                ),
                              ),
                            ],
                          ),
                        ),
                        Expanded(
                          child: HoriScrollList(),
                          flex: 2,
                        ),
                        Padding(
                          padding: const EdgeInsets.fromLTRB(8, 12, 8, 2),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                "Best Sellers",
                                style: TextStyle(
                                  fontSize: 18,
                                  fontWeight: FontWeight.w500,
                                  color: Mythemes.darkbluishcolor,
                                ),
                              ),
                              Text(
                                "See all",
                                style: TextStyle(
                                  fontSize: 15,
                                  fontWeight: FontWeight.w500,
                                  color: Colors.black54,
                                ),
                              ),
                            ],
                          ),
                        ),
                        Expanded(
                          child: BestSellers(),
                          flex: 3,
                        ),
                        Expanded(child: ProductModel(),flex: 3,),
                      ],
                    ),
                  )
                : Center(child: CircularProgressIndicator()),
          ),
        ),
      ),
    );
  }
}

产品型号class

class ProductModel extends StatelessWidget {
  const ProductModel({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: CatalogModel.items.length,
        itemBuilder: (context, index) {
          final catalogitem = CatalogModel.items[index];
          return InkWell(
              onTap: () {
                Navigator.push(
                    context,
                    MaterialPageRoute(
                        builder: (context) =>
                            ProductCart(item: CatalogModel.items[index])));
              },
              child: ProductView(item: catalogitem));
        });
  }
}

您的SingleChildScrollView处理页面滚动事件。 对于垂直可滚动小部件的 rest 包括NeverScrollableScrollPhysics(), 此外,您可以使用primary: false,

ListView.builder(
 physics: NeverScrollableScrollPhysics(),

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM