xuelongqy / flutter_easy_refresh

A flutter widget that provides pull-down refresh and pull-up load.
https://xuelongqy.github.io/flutter_easy_refresh/
MIT License
3.84k stars 628 forks source link

在 item项里添加ListView导致EasyRefresh 下拉组件不回弹 一直在刷新(onRefresh一直回调) #750

Closed liyofx closed 11 months ago

liyofx commented 11 months ago
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';

class TestPage extends StatefulWidget {
  const TestPage({super.key});

  @override
  State<TestPage> createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {
  List<String> list = [];
  bool isRefresher = true;

  final EasyRefreshController controller = EasyRefreshController(
    controlFinishRefresh: true,
    controlFinishLoad: true,
  );
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: EasyRefresh(
        controller: controller,
        header: const CupertinoHeader(),
        footer: const CupertinoFooter(),
        triggerAxis: Axis.vertical,
        refreshOnStart: true,
        onRefresh: () async {
          print("#########");
          await Future.delayed(Duration(seconds: 2));
          setState(() {
            for (var i = 0; i < 30; i++) {
              list.add("Item  ${i}");
            }
          });
          controller.finishRefresh();
          controller.resetFooter();
        },
        onLoad: null,
        child: _buildChild(list),
      ),
    );
  }

  Widget _buildChild(models) {
    return CustomScrollView(
      slivers: [
        SliverToBoxAdapter(
          child: Container(
            height: 50,
            color: Colors.lightBlue,
            child: const Text("Header"),
          ),
        ),
        SliverGrid.count(
          crossAxisCount: 2,
          childAspectRatio: 2.5,
          children: List.generate(
              models.length,
              (index) => Container(
                    alignment: Alignment.center,
                    decoration: const BoxDecoration(color: Colors.amber),
                    margin: const EdgeInsets.all(10),
                    child: Column(
                      children: [
                        Text("${models[index]}"),
                        SizedBox(
                          height: 30,
                          child: ListView.builder(
                            scrollDirection: Axis.horizontal,
                            itemBuilder: (context, index) => Text("data  $index "),
                            itemCount: 9,
                          ),
                        ),
                      ],
                    ),
                  )),
        )
      ],
    );
  }
}

easy_refresh: ^3.3.2+1

在 item项里添加ListView导致EasyRefresh 下拉组件不回弹 一直在刷新(onRefresh回调)。下面是视频效果:

https://github.com/xuelongqy/flutter_easy_refresh/assets/6176478/aff8eac1-23c5-47fd-8d10-230d96ebb2bc

liyofx commented 11 months ago

child作用域内,所有滚动组件会公用一个physics。如果有滚动嵌套,请使用EasyRefresh.builder或用ScrollConfiguration设置作用域 已解决