Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EasyRefresh 无法上弹 #870

Open
WuMingke opened this issue Oct 24, 2024 · 0 comments
Open

EasyRefresh 无法上弹 #870

WuMingke opened this issue Oct 24, 2024 · 0 comments

Comments

@WuMingke
Copy link

如下demo,搭配 AnimatedList,EasyRefresh 在执行刷新动画时点击按钮,完成刷新后,无法上弹:

void main() {
  runApp(const MyHome());
}

class MyHome extends StatelessWidget {
  const MyHome({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        body: SafeArea(child: MyBody2()),
      ),
    );
  }
}

class MyBody2 extends StatelessWidget {
  const MyBody2({super.key});

  @override
  Widget build(BuildContext context) {
    final animatedListKey = GlobalKey<AnimatedListState>();
    final data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

    return EasyRefresh(
      child: CustomScrollView(
        physics: const AlwaysScrollableScrollPhysics(),
        slivers: [
          SliverToBoxAdapter(
            child: SizedBox(
              height: 500,
              child: AnimatedList(
                key: animatedListKey,
                shrinkWrap: true,
                scrollDirection: Axis.vertical,
                initialItemCount: data.length,
                itemBuilder: (context, index, animation) {
                  return FadeTransition(
                    opacity: animation
                        .drive(CurveTween(curve: Curves.easeIn))
                        .drive(Tween<double>(begin: 0, end: 1)),
                    child: SizedBox(
                      height: 100,
                      child: Text(key: ObjectKey(index), 'data ${data[index]}'),
                    ),
                  );
                },
              ),
            ),
          ),
          SliverToBoxAdapter(
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                ElevatedButton(
                  onPressed: () {
                    /// 点击循环列表
                    final index = data.length - 1;
                    final item = data[index];
                    animatedListKey.currentState?.removeItem(index,
                        (context, animation) {
                      return const SizedBox.shrink();
                    });
                    data
                      ..removeAt(index)
                      ..insert(0, item);
                    animatedListKey.currentState?.insertItem(0);
                  },
                  child: const Text('loop'),
                ),
              ],
            ),
          )
        ],
      ),
      onRefresh: () {
      },
    );
  }
}

26186c549d5b068abafc0fa96a2e928b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant