Created
July 4, 2021 21:11
-
-
Save IsmailAlamKhan/efa1839d21d38089ba39f929ce87fd63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(App()); | |
class App extends StatelessWidget { | |
App({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: HomeScreen(), | |
); | |
} | |
} | |
class HomeScreen extends StatefulWidget { | |
@override | |
_HomeScreenState createState() => _HomeScreenState(); | |
} | |
class _HomeScreenState extends State<HomeScreen> { | |
late final PageController controller; | |
late List<int> stories = [1,2,3,4,5]; | |
@override | |
void initState() { | |
super.initState(); | |
controller = PageController(initialPage: 0); | |
} | |
void toPage(int index) async { | |
print("ANIMATION STARTED"); | |
controller.animateToPage(index, | |
duration: Duration(milliseconds: 400), curve: Curves.easeInOut); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return PageView.builder( | |
controller: controller, | |
scrollDirection: Axis.horizontal, | |
itemCount: stories.length, | |
itemBuilder: (BuildContext context, int index) { | |
return Column( | |
children: [ | |
Expanded( | |
child: Center( | |
child: ElevatedButton( | |
onPressed: () => toPage(index+1), | |
child: Text("Go to next page $index")), | |
), | |
), | |
], | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment