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

boundcing scroll offset #4

Closed
yyong37 opened this issue Feb 27, 2022 · 4 comments
Closed

boundcing scroll offset #4

yyong37 opened this issue Feb 27, 2022 · 4 comments

Comments

@yyong37
Copy link

yyong37 commented Feb 27, 2022

预期: 下拉回弹会定位到顶部第一个元素.
但是现在会回弹至第2,3个元素才停止

expect: bouncing and stop edge first item

----screen top edge-----
------  <-- expect stop position
-------
------- <-- current version stop scroll offset
-------
------- 

class BingoPage extends StatefulWidget {
  @override
  State<BingoPage> createState() => _BingoPageState();
}

class _BingoPageState extends State<BingoPage> {
  final logic = Get.find<BingoLogic>();

  final data = <String>[];

  @override
  void initState() {
    // mock chat list insert data
    Timer.periodic(Duration(seconds: 1), (timer) {
      setState(() {
        data.insert(0, DateTime.now().toString());
      });
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: FlutterListView(
            reverse: true,
            delegate: FlutterListViewDelegate(
              (BuildContext context, int index) => ListTile(title: Text('List Item ${data[index]}')),
              childCount: data.length,
              keepPosition: true,
            )));
  }
}

@robert-bitguild
Copy link
Collaborator

@rizzi37 I can't reproduce the issue that you mentioned. Please copy/paste the whole FlutterListView element to me to verify it.

  1. Did you have set reverse to true,
  2. Did you have wrap SmartRefresher or other refresh element on it.

@yyong37
Copy link
Author

yyong37 commented Feb 28, 2022

@robert-bitguild thanks for your fast reply, I have updated my origin issue with the same code.

@yyong37 yyong37 changed the title 顶部下拉回弹过大 boundcing scroll offset Feb 28, 2022
@robert-bitguild
Copy link
Collaborator

@rizzi37 我认为这个是正常行为,我对比了ListView的官方源码(ListView也有这个问题),这是因为你在下拉过程中,Timer.periodic(Duration(seconds: 1), (timer) 里创建了新的项而导致滚动后退了。现实情况下,这种情况一般不会考虑,即下拉过程中有UI刷新。

另外,keepPosition: true时最好实现 onItemKey: (index) ,否测keepPosition不会成效。因为我不知道你insert的行在那里。onItemKey要返加该行的唯一值。

  return Scaffold(
        body: FlutterListView(
            reverse: true,
            delegate: FlutterListViewDelegate(
              (BuildContext context, int index) =>
                  ListTile(title: Text('List Item ${data[index]}')),
              childCount: data.length,
              keepPosition: true,
              onItemKey: (index) {
                return data[index];
              },
            )));

@yyong37
Copy link
Author

yyong37 commented Feb 28, 2022

收到.再次表示感谢.

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

2 participants