Flutter中ListView中的问题滚动或“嵌套滚动”

问题描述 投票:0回答:1

因此,如所附视频所示,滚动时出现问题。它应该像一个无限滚动视图(就像在Facebook的应用程序新闻提要上一样)

问题是,父ListView中似乎有一个“嵌套”滚动。我怎样才能解决这个问题?请协助

VIDEO HERE (I don't know how to attach a video here so I put it on youtube)

我的主页代码是这里,“更多优惠”部分应该像在Facebook的新闻源上一样不断地从Firebase后端生成数据:

  @override
  Widget build(BuildContext context) {


    width = MediaQuery.of(context).size.width;

    return SafeArea(
        child: Scaffold(
          backgroundColor: Color(0xFF0d192a),
        appBar: CustomAppBar(height: 60),
        // appBar: CustomAppBar(height: 70),
        drawer: DrawerNiVlad(),

        body: ListView(
          //vlad
          children: <Widget>[

           // some widgets here

          ArlTitleText('More Offers'),
          MoreOffers(), <= The widget that has a "nested scroll"
          sb5,

MoreOffers小部件代码

Widget build(BuildContext context) {
    return StreamBuilder(
        initialData: List<DiscountEntity>(),
        stream: _moreOffersBloc.listDiscounts3Flux,
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          if (!snapshot.hasData) return Container(height: 1, width: 1);
          return ListView.builder(
            shrinkWrap: true,
            padding: EdgeInsets.symmetric(horizontal: 5.0, vertical: 5.0),
            scrollDirection: Axis.vertical,
            itemCount: snapshot.data.length,
            itemBuilder: (BuildContext context, int index) {
              DiscountEntity discount =
                  snapshot.data[index] as DiscountEntity;
              return Container(
                decoration: BoxDecoration(
                    // border: Border(bottom: BorderSide()),
                    ),
                child: Card(
                    color: Color(0xFF0d192a),
                    child: Padding(
                      padding: const EdgeInsets.symmetric(
                          horizontal: 5.0, vertical: 5.0),
                      child: Stack(
                        children: <Widget>[
                          InkWell(
                            onTap: () {
                              print('123123');
                              Navigator.push(
                                context,
                                MaterialPageRoute(
                                  builder: (_) => DetailsDiscountPage(
                                    discount: discount,
                                  ),
                                ),
                              );
                            }, // button pressed
                            child: Container(
                              width: 100.0,
                              height: 100.0,
                              decoration: BoxDecoration(
                                borderRadius:
                                    BorderRadius.all(Radius.circular(5.0)),
                                color: Colors.black,
                              ),
                              child: Image.network(
                                // 'asdkmnajhkalskca',
                                discount.imageUrl.Url,
                                fit: BoxFit.cover,
                                loadingBuilder: (BuildContext context,
                                    Widget child,
                                    ImageChunkEvent loadingProgress) {
                                  if (loadingProgress == null) return child;
                                  return Center(
                                    child: CircularProgressIndicator(
                                      backgroundColor: Colors.white,
                                      valueColor:
                                          AlwaysStoppedAnimation<Color>(
                                              goldColor),
                                      value: loadingProgress
                                                  .expectedTotalBytes !=
                                              null
                                          ? loadingProgress
                                                  .cumulativeBytesLoaded /
                                              loadingProgress
                                                  .expectedTotalBytes
                                          : null,
                                    ),
                                  );
                                },
                              ),
                            ),
                          ),
                          Positioned(
                            left: 110,
                            top: 1,
                            child: InkWell(
                              onTap: () {
                                print('asdasdasdas');
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(
                                    builder: (_) => DetailsDiscountPage(
                                      discount: discount,
                                    ),
                                  ),
                                );
                              }, // button pressed
                              child: Container(
                                child: Text(
                                  discount.name,
                                  style: TextStyle(
                                      color: goldColor,
                                      fontSize: 15,
                                      letterSpacing: 1,
                                      fontFamily: 'Lato',
                                      fontWeight: FontWeight.bold),
                                ),
                              ),
                            ),
                          ),
                          Positioned(
                            left: 110,
                            top: 17,
                            child: Container(
                              child: Text(
                                //  discount.type,
                                'category',
                                style: TextStyle(
                                    color: Color(0xff7a7a7a),
                                    fontSize: 15,
                                    letterSpacing: 1,
                                    fontFamily: 'Lato',
                                    fontWeight: FontWeight.normal),
                              ),
                            ),
                          ),
                          Positioned(
                            left: 110,
                            top: 35,
                            child: Container(
                                child: Row(
                              children: <Widget>[
                                Icon(
                                  Icons.calendar_today,
                                  color: Color(0xff7a7a7a),
                                  size: 15,
                                ),
                                Text(
                                  'Jan 1, 2020 - Dec 1, 2020',
                                  style: TextStyle(
                                      color: Color(0xff7a7a7a),
                                      fontSize: 15,
                                      letterSpacing: 1,
                                      fontFamily: 'Lato',
                                      fontWeight: FontWeight.normal),
                                ),
                              ],
                            )),
                          ),
                        ],
                      ),
                    )),
              );
            },
          );
        });
android flutter flutter-layout flutter-dependencies
1个回答
0
投票

ListView.builder中,添加primary属性并将其值设置为false

return ListView.builder(
  primary: false, // add this line 
  shrinkWrap: true,
  ... etc ...
);
© www.soinside.com 2019 - 2024. All rights reserved.