0

Hello i`m new in flutter. I made a special listView for myself and made a controller for it. In the main page, I have called my own list view and I have a button that I want to execute the following method by pressing it from the Main class and my list view scrolls inside another class. scroll method:

void _animateToIndex(int index) {
_controller.animateTo(
index * 50,
duration: Duration(seconds: 1),
curve: Curves.fastOutSlowIn,
  );
}

In fact, I want to execute the method of another class that contains my scrollview from the Main class.

my listView class:

class CustomNumberScroller extends StatefulWidget {

const CustomNumberScroller(
  {Key? key, required this.curStep, required this.pageNumberOfMainDart})
  : super(key: key);

@override
State<CustomNumberScroller> createState() => _CustomNumberScrollerState();
}

final dataKey = new GlobalKey();

final ScrollController _controller = ScrollController();

void _animateToIndex(int index) {
_controller.animateTo(
index * 50,
duration: Duration(seconds: 1),
curve: Curves.fastOutSlowIn,
 );
}

class _CustomNumberScrollerState extends State<CustomNumberScroller> {
 @override
 Widget build(BuildContext context) {
 Size media = MediaQuery.of(context).size;

 return ...

   }
}

1 Answers1

0

you can use state management as provide and put scroll controller in class and access to controller in any place in widget tree

hope that helps you

get started with provider

Abd Alazeez
  • 126
  • 1
  • 5