【问题标题】:Scrolling in its own container in expanded widget flutter, How can i make it scroll through the whole page ? ( Flutter )在扩展的小部件颤动中滚动它自己的容器,我怎样才能让它滚动整个页面? (颤振)
【发布时间】:2022-01-13 18:06:01
【问题描述】:

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

主页类

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()),
          ),
        ),
      ),
    );
  }
}

ProductModel 类

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));
        });
  }
}

【问题讨论】:

    标签: android flutter dart


    【解决方案1】:

    您的SingleChildScrollView 处理页面滚动事件。 对于垂直可滚动小部件的其余部分,包括NeverScrollableScrollPhysics(),。另外,您可以使用primary: false,进行测试

    ListView.builder(
     physics: NeverScrollableScrollPhysics(),
    

    【讨论】:

    • 它不起作用,设置物理后:NeverScrollableScrollPhysics() 现在容器也不滚动了。
    • 请确保不要将其包含在SingleChildScrollView 和水平滚动中,同时使用CustomScrollViewNestedScrollView 将是更好的选择
    猜你喜欢
    • 2020-06-22
    • 2019-05-23
    • 2019-04-10
    • 2022-11-04
    • 2021-09-25
    • 2019-09-23
    • 2020-11-11
    • 2020-08-02
    • 1970-01-01
    相关资源
    最近更新 更多