quire-io/scroll-to-index

scroll_to_index is not working nested scroll view (ListView.buielder() insider inside Listview)

imSanjaySoni opened this issue · 3 comments

Can you please help, How can Use scroll_to_index list inside a list?

 @override
 Widget build(BuildContext context) {
   return Scaffold(
     appBar: AppBar(
       // Here we take the value from the MyHomePage object that was created by
       // the App.build method, and use it to set our appbar title.
       title: Text(widget.title),
     ),
     body: ListView(
       shrinkWrap: true,
       children: [
         Container(
           color: Colors.amber,
           height: 40,
         ),
         ListView.builder(
             shrinkWrap: true,
             controller: controller,
             itemCount: 100,
             physics: NeverScrollableScrollPhysics(),
             itemBuilder: (c, i) => AutoScrollTag(
                   key: ValueKey(i),
                   controller: controller,
                   index: i,
                   child: Container(
                     height: 200,
                     color: Colors.red,
                     margin: EdgeInsets.all(16),
                   ),
                 )),
       ],
     ),
     floatingActionButton: FloatingActionButton(
       onPressed: _incrementCounter,
       tooltip: 'Increment',
       child: Icon(Icons.add),
     ), // This trailing comma makes auto-formatting nicer for build methods.
   );
 }
}

just merged the container and list view builder into custom scroll view, please see the migration example: the section of Transitioning to CustomScrollView in https://api.flutter.dev/flutter/widgets/ListView-class.html.

@jerrywell Can you please explain the reason for this issue? I am facing a similar issue where .highlight() is working as expected but .scrollToIndex() is not scrolling the list item even after transitioning to CustomScrollView.

the single level children should work fine in this package. you can post the issue if it doesn't work.