diff --git a/packages/flutter/lib/src/widgets/page_view.dart b/packages/flutter/lib/src/widgets/page_view.dart index d7d28f9463c..5d69fd7ee74 100644 --- a/packages/flutter/lib/src/widgets/page_view.dart +++ b/packages/flutter/lib/src/widgets/page_view.dart @@ -36,6 +36,87 @@ import 'viewport.dart'; /// See also: /// /// * [PageView], which is the widget this object controls. +/// +/// {@tool sample} +/// +/// This widget introduces a [MaterialApp], [Scaffold] and [PageView] with two pages +/// using the default constructor. Both pages contain a [RaisedButton] allowing you +/// to animate the [PageView] using a [PageController]. +/// +/// ```dart +/// class MyPageView extends StatefulWidget { +/// MyPageView({Key key}) : super(key: key); +/// +/// _MyPageViewState createState() => _MyPageViewState(); +/// } +/// +/// class _MyPageViewState extends State { +/// PageController _pageController; +/// +/// @override +/// void initState() { +/// super.initState(); +/// _pageController = PageController(); +/// } +/// +/// @override +/// void dispose() { +/// _pageController.dispose(); +/// super.dispose(); +/// } +/// +/// @override +/// Widget build(BuildContext context) { +/// return MaterialApp( +/// home: Scaffold( +/// body: PageView( +/// controller: _pageController, +/// children: [ +/// Container( +/// color: Colors.red, +/// child: Center( +/// child: RaisedButton( +/// color: Colors.white, +/// onPressed: () { +/// if (_pageController.hasClients) { +/// _pageController.animateToPage( +/// 1, +/// duration: const Duration(milliseconds: 400), +/// curve: Curves.easeInOut, +/// ); +/// } +/// }, +/// child: Text('Next'), +/// ), +/// ), +/// ), +/// Container( +/// color: Colors.blue, +/// child: Center( +/// child: RaisedButton( +/// color: Colors.white, +/// onPressed: () { +/// if (_pageController.hasClients) { +/// _pageController.animateToPage( +/// 0, +/// duration: const Duration(milliseconds: 400), +/// curve: Curves.easeInOut, +/// ); +/// } +/// }, +/// child: Text('Previous'), +/// ), +/// ), +/// ), +/// ], +/// ), +/// ), +/// ); +/// } +/// } +/// +/// ``` +/// {@end-tool} class PageController extends ScrollController { /// Creates a page controller. ///