mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Added tool sample for PageController (#34137)
* Added tool sample for PageController * Fixed text directionality bug
This commit is contained in:
parent
05e92c828b
commit
d850d69c3f
@ -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<MyPageView> {
|
||||
/// 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.
|
||||
///
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user