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

ScrollablePositionedList can not jump to end without animation #151

Open
asjqkkkk opened this issue Jul 8, 2020 · 5 comments
Open

ScrollablePositionedList can not jump to end without animation #151

asjqkkkk opened this issue Jul 8, 2020 · 5 comments
Labels
p: scrollable_positioned_list Related to package:scrollable_positioned_list SPL-scroll to end

Comments

@asjqkkkk
Copy link
Contributor

asjqkkkk commented Jul 8, 2020

Problem description

demo

Enviroment

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.17.5, on Mac OS X 10.15.5 19F101, locale zh-Hans-CN)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
[✓] Android Studio (version 4.0)
[✓] Connected device (1 available)

scrollable_positioned_list: ^0.1.6

Expected behavior

use itemScrollController.jumpTo(...) should not trigger animation

Sample code

import 'dart:math';
import 'package:flutter/material.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  final List<String> curList = [];
  final ItemScrollController itemScrollController = ItemScrollController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: <Widget>[
          IconButton(icon: Icon(Icons.refresh), onPressed: (){
            buildTextList();
            setState(() { });
            Future.delayed(Duration(milliseconds: 100,), (){
              itemScrollController.jumpTo(index: curList.length);
            });
          })
        ],
      ),
      body: ScrollablePositionedList.builder(
        itemScrollController: itemScrollController,
        itemCount: curList.length,
        itemBuilder: (ctx, index){
          final cur = curList[index];
          return ListTile(title: Text(cur),onTap: (){},);
        },
      ),
    );
  }

  void buildTextList() => curList.add(Random().nextInt(1000).toString());
}
@jamesderlin jamesderlin added p: scrollable_positioned_list Related to package:scrollable_positioned_list SPL-scroll to end labels Sep 18, 2020
@jamesderlin
Copy link
Collaborator

jamesderlin commented Jan 21, 2021

This is observable with the example app: tapping "Jump to 0" with an alignment > 0 when already scrolled to the top triggers a bounce animation, as does "Jump to 5000" (the end) with an alignment < 1 when already scrolled to the end.

DamirDautov added a commit to DamirDautov/flutter.widgets that referenced this issue Jun 7, 2021
DamirDautov added a commit to DamirDautov/flutter.widgets that referenced this issue Jun 7, 2021
@DamirDautov
Copy link

If what you want to do is only jump to one particular item, so maybe this workaround I made can help. There's a restriction of Viewport, so no overscroll is allowed, that's the disadvantage.
Also when you change the target item some strange (for me) thing happens: at first frame heights of leadingNegativeChild and trailingPositiveChild are not correct, like some list items are not being calculated. So it looks buggy, but without this workaround list would just have another animation.
So maybe anyone can look closely to that code, maybe you will go through it and find some final fix, I dunno.
Also this discussion should really be considered

@ModWU
Copy link

ModWU commented Nov 19, 2021

Can you calculate the items below the center item or above according viewport height before the animation?

@ma125125t
Copy link

@DamirDautov Thank you for your workaround solution.This solved my problem.Otherwise,I need to calculate each dynamic list item to scroll to correct offset.You saved my time.

hoanglm-guide-vn pushed a commit to guide-inc-org/guide-flutter_widgets that referenced this issue Dec 28, 2022
@felipecastrosales
Copy link

Any news about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p: scrollable_positioned_list Related to package:scrollable_positioned_list SPL-scroll to end
Projects
None yet
Development

No branches or pull requests

6 participants