Skip to content

Instantly share code, notes, and snippets.

@FlutterZeroGit
Last active August 2, 2022 23:40
Show Gist options
  • Save FlutterZeroGit/29ff1ebab1997a19005c2d102b11e7c0 to your computer and use it in GitHub Desktop.
Save FlutterZeroGit/29ff1ebab1997a19005c2d102b11e7c0 to your computer and use it in GitHub Desktop.
PageController animateToPage
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final controller = PageController();
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('FlutterZero'),
),
body: PageView(
controller: controller,
children: [
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Page 1'),
SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () => controller.animateToPage(
1,
duration: Duration(seconds: 1),
curve: Curves.easeIn,
),
child: Text('Page 2に移動'),
)
],
),
),
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Page 2'),
SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () => controller.animateToPage(
0,
duration: Duration(seconds: 1),
curve: Curves.easeIn,
),
child: Text('Page 1に移動'),
)
],
),
)
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment