GithubHelp home page GithubHelp logo

Comments (11)

oseiasmribeiro avatar oseiasmribeiro commented on August 23, 2024

Tarobins, when you make a paging scheme, like in a book, sending the initialScrollIndex always to position 0 the ScrollablePositionedList works perfectly. Now imagine a scenario where I do a words search in a book and by clicking on one of the results the ScrollablePositionedList will build and jump to a specific paragraph; So far so good, after that, I need to navigate to the previous or next chapter, I need to rebuild the state to bring in the new chapter by adding a new value to initialScrollIndex, in that case the initial index that corresponds to the first value of initialScrollIndex, it does not update. If of the itemCount is greater than this index value, not problem, because the range is larger, but if itemCount is smaller then the bug happens.

from flutter.widgets.

oseiasmribeiro avatar oseiasmribeiro commented on August 23, 2024

Even using JumpTo gives the same problem.

from flutter.widgets.

oseiasmribeiro avatar oseiasmribeiro commented on August 23, 2024

This issue has been resolved!

from flutter.widgets.

arteminthesky avatar arteminthesky commented on August 23, 2024

@oseiasmribeiro hi! How you resolve it?

from flutter.widgets.

AurelianTimu avatar AurelianTimu commented on August 23, 2024

How did you solve it? I am experiencing exactly the same issue.

Edit:
I solved it by keeping track of removed list items and returning widgets from the itemBuilder accordingly.

from flutter.widgets.

arteminthesky avatar arteminthesky commented on August 23, 2024

@AurelianTimu сould you give more information about your solution?

from flutter.widgets.

oseiasmribeiro avatar oseiasmribeiro commented on August 23, 2024

I simply upgraded to the latest version of the ScrollablePositionedList widget and it worked. Could you post some code examples showing the error? I can reopen the bug.

from flutter.widgets.

AurelianTimu avatar AurelianTimu commented on August 23, 2024

@iKrupp

See the comment I left in #77.

from flutter.widgets.

vabawen avatar vabawen commented on August 23, 2024

@oseiasmribeiro I got rangeError with this code:

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  List<int> array1;
  List<int> array2;
  List<int> array;
  int initialIndex;

  @override
  void initState() {
    super.initState();
    array1 = List.generate(30, (index) => index);
    array2 = List.generate(10, (index) => index);
    array = array1;
    initialIndex = 15;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Expanded(
              child: ScrollablePositionedList.builder(
                initialScrollIndex: initialIndex,
                itemBuilder: (context, index) => Container(
                  alignment: Alignment.bottomCenter,
                  padding: EdgeInsets.symmetric(vertical: 20),
                  child: Text('${array[index]}'),
                ),
                itemCount: array.length,
              )
            ),
            Divider(),
            OutlineButton(
              child: Text('Load array2'),
              onPressed: () {
                setState(() {
                  array = array2;
                  initialIndex = 0;
                });
              },
            ),
          ],
        ),
      ), 
    );
  }
}

from flutter.widgets.

oseiasmribeiro avatar oseiasmribeiro commented on August 23, 2024

I reopened the problem. Maybe the problem doesn't happen to me anymore because I wrapped the ScrollablePositionedList in a PageView. I will make my code available for you to analyze:
https://drive.google.com/file/d/1P88W7Mr2tA-RSeyJFiOU9Kv_Y_8Xt7oE/view?usp=sharing

from flutter.widgets.

oseiasmribeiro avatar oseiasmribeiro commented on August 23, 2024

@vabawen, I don't change the list dynamically as in your example. I use PageView for that! But I did a test with your code and for me the problem also occurs.

from flutter.widgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.