I'm trying to access the Page Controller of one screen into the other screen. Let's say there are two screens (Screen A and Screen B)
Screen A Code
class ScreenA extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[200],
body: SafeArea(child: ListView(
children: [
for (int i = 0; i < 5; i++) // Both are having same number of loops (Screen A and Screen B)
TextButton(
onPressed: (){
_pageController.animateToPage( // This should redirect them to their respective PageView childrens of ScreenB
${i},
duration: const Duration(milliseconds: 400),
curve: Curves.easeInOut,
);
},
child: Container(
child: Text('Click Me'),
),
)
],
),
),
);
}
}
Screen B Code
class _ScreenBState extends State<shlokPage> {
final PageController _pageController = PageController(); // I need to access this controller in Screen A
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[200],
body: SafeArea(
child: PageView(
controller: _pageController,
children: [
for (int i = 0; i < 5; i++) // Both are having same number of loops (Screen A and Screen B)
Container(
color: Colors.red,
child: Center(
child: Text('Hello World'),
),
),
],
),
),
);
}
}
So I'm trying to jump from Screen A to Screen B (to their respective children) with the help of a page controller (pageview widget) So basically, I'm trying to link ListView with the PageView (there are buttons in the ListView that needs to go to PageView children)