flutter/dev/manual_tests/lib/page_view.dart

153 lines
4 KiB
Dart
Raw Normal View History

// Copyright 2014 The Flutter Authors. All rights reserved.
Adds PageableList, other scrolling related changes and fixes - PageableList extends ScrollableList One fixed width or height item is visible and centered at a time. Fling and drag gestures scroll to the next/previous item. - Scrollable.scrollTo(), Scrollable.scrollBy(), ensureWidgetIsVisible() API changed The named animation parameter for these methods was replaced by duration and curve. All of the methods now return a Future. The Future completes when the scroll does. This change eliminates the need for Scrollable to temporarily take ownership of a ValueAnimation object (see #645). - Using Future.then() instead of an AnimationPerformance status listener In ensure_visible.dart _handleTap() uses ensureWidgetIsVisible() to center the card roughly as before and then. When the implicit scroll animation is complete, it changes the centered card's label font. The change is made when the Future returned by ensureWidgetIsVisible() completes. - FixedHeightScrollable's itemHeight parameter is now itemExtent If scrollDirection is ScrollDirection.vertical (the default) then itemExtent should be the height of each item; otherwise it should be the width of each item. Replaced _velocityForFlingGesture() in scrollable.dart with Scrollable._eventVelocity() The original version clamped pixels/ms against pixels/sec constants. The new version also deals with scrollDirection. - Plumbed scrollDirection though FixedHeightScrollable and ScrollableList Both classes should now support horizontal scrolling.
2015-08-17 23:48:13 +00:00
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
2015-10-10 03:44:52 +00:00
import 'package:flutter/material.dart';
Adds PageableList, other scrolling related changes and fixes - PageableList extends ScrollableList One fixed width or height item is visible and centered at a time. Fling and drag gestures scroll to the next/previous item. - Scrollable.scrollTo(), Scrollable.scrollBy(), ensureWidgetIsVisible() API changed The named animation parameter for these methods was replaced by duration and curve. All of the methods now return a Future. The Future completes when the scroll does. This change eliminates the need for Scrollable to temporarily take ownership of a ValueAnimation object (see #645). - Using Future.then() instead of an AnimationPerformance status listener In ensure_visible.dart _handleTap() uses ensureWidgetIsVisible() to center the card roughly as before and then. When the implicit scroll animation is complete, it changes the centered card's label font. The change is made when the Future returned by ensureWidgetIsVisible() completes. - FixedHeightScrollable's itemHeight parameter is now itemExtent If scrollDirection is ScrollDirection.vertical (the default) then itemExtent should be the height of each item; otherwise it should be the width of each item. Replaced _velocityForFlingGesture() in scrollable.dart with Scrollable._eventVelocity() The original version clamped pixels/ms against pixels/sec constants. The new version also deals with scrollDirection. - Plumbed scrollDirection though FixedHeightScrollable and ScrollableList Both classes should now support horizontal scrolling.
2015-08-17 23:48:13 +00:00
class CardModel {
CardModel(this.value, this.size, this.color);
int value;
Size size;
Color color;
String get label => 'Card $value';
Key get key => ObjectKey(this);
Adds PageableList, other scrolling related changes and fixes - PageableList extends ScrollableList One fixed width or height item is visible and centered at a time. Fling and drag gestures scroll to the next/previous item. - Scrollable.scrollTo(), Scrollable.scrollBy(), ensureWidgetIsVisible() API changed The named animation parameter for these methods was replaced by duration and curve. All of the methods now return a Future. The Future completes when the scroll does. This change eliminates the need for Scrollable to temporarily take ownership of a ValueAnimation object (see #645). - Using Future.then() instead of an AnimationPerformance status listener In ensure_visible.dart _handleTap() uses ensureWidgetIsVisible() to center the card roughly as before and then. When the implicit scroll animation is complete, it changes the centered card's label font. The change is made when the Future returned by ensureWidgetIsVisible() completes. - FixedHeightScrollable's itemHeight parameter is now itemExtent If scrollDirection is ScrollDirection.vertical (the default) then itemExtent should be the height of each item; otherwise it should be the width of each item. Replaced _velocityForFlingGesture() in scrollable.dart with Scrollable._eventVelocity() The original version clamped pixels/ms against pixels/sec constants. The new version also deals with scrollDirection. - Plumbed scrollDirection though FixedHeightScrollable and ScrollableList Both classes should now support horizontal scrolling.
2015-08-17 23:48:13 +00:00
}
class PageViewApp extends StatefulWidget {
@override
PageViewAppState createState() => PageViewAppState();
2015-09-24 22:31:06 +00:00
}
Adds PageableList, other scrolling related changes and fixes - PageableList extends ScrollableList One fixed width or height item is visible and centered at a time. Fling and drag gestures scroll to the next/previous item. - Scrollable.scrollTo(), Scrollable.scrollBy(), ensureWidgetIsVisible() API changed The named animation parameter for these methods was replaced by duration and curve. All of the methods now return a Future. The Future completes when the scroll does. This change eliminates the need for Scrollable to temporarily take ownership of a ValueAnimation object (see #645). - Using Future.then() instead of an AnimationPerformance status listener In ensure_visible.dart _handleTap() uses ensureWidgetIsVisible() to center the card roughly as before and then. When the implicit scroll animation is complete, it changes the centered card's label font. The change is made when the Future returned by ensureWidgetIsVisible() completes. - FixedHeightScrollable's itemHeight parameter is now itemExtent If scrollDirection is ScrollDirection.vertical (the default) then itemExtent should be the height of each item; otherwise it should be the width of each item. Replaced _velocityForFlingGesture() in scrollable.dart with Scrollable._eventVelocity() The original version clamped pixels/ms against pixels/sec constants. The new version also deals with scrollDirection. - Plumbed scrollDirection though FixedHeightScrollable and ScrollableList Both classes should now support horizontal scrolling.
2015-08-17 23:48:13 +00:00
class PageViewAppState extends State<PageViewApp> {
@override
void initState() {
super.initState();
const List<Size> cardSizes = <Size>[
Size(100.0, 300.0),
Size(300.0, 100.0),
Size(200.0, 400.0),
Size(400.0, 400.0),
Size(300.0, 400.0),
];
Adds PageableList, other scrolling related changes and fixes - PageableList extends ScrollableList One fixed width or height item is visible and centered at a time. Fling and drag gestures scroll to the next/previous item. - Scrollable.scrollTo(), Scrollable.scrollBy(), ensureWidgetIsVisible() API changed The named animation parameter for these methods was replaced by duration and curve. All of the methods now return a Future. The Future completes when the scroll does. This change eliminates the need for Scrollable to temporarily take ownership of a ValueAnimation object (see #645). - Using Future.then() instead of an AnimationPerformance status listener In ensure_visible.dart _handleTap() uses ensureWidgetIsVisible() to center the card roughly as before and then. When the implicit scroll animation is complete, it changes the centered card's label font. The change is made when the Future returned by ensureWidgetIsVisible() completes. - FixedHeightScrollable's itemHeight parameter is now itemExtent If scrollDirection is ScrollDirection.vertical (the default) then itemExtent should be the height of each item; otherwise it should be the width of each item. Replaced _velocityForFlingGesture() in scrollable.dart with Scrollable._eventVelocity() The original version clamped pixels/ms against pixels/sec constants. The new version also deals with scrollDirection. - Plumbed scrollDirection though FixedHeightScrollable and ScrollableList Both classes should now support horizontal scrolling.
2015-08-17 23:48:13 +00:00
cardModels = List<CardModel>.generate(cardSizes.length, (int i) {
final Color color = Color.lerp(Colors.red.shade300, Colors.blue.shade900, i / cardSizes.length);
return CardModel(i, cardSizes[i], color);
Adds PageableList, other scrolling related changes and fixes - PageableList extends ScrollableList One fixed width or height item is visible and centered at a time. Fling and drag gestures scroll to the next/previous item. - Scrollable.scrollTo(), Scrollable.scrollBy(), ensureWidgetIsVisible() API changed The named animation parameter for these methods was replaced by duration and curve. All of the methods now return a Future. The Future completes when the scroll does. This change eliminates the need for Scrollable to temporarily take ownership of a ValueAnimation object (see #645). - Using Future.then() instead of an AnimationPerformance status listener In ensure_visible.dart _handleTap() uses ensureWidgetIsVisible() to center the card roughly as before and then. When the implicit scroll animation is complete, it changes the centered card's label font. The change is made when the Future returned by ensureWidgetIsVisible() completes. - FixedHeightScrollable's itemHeight parameter is now itemExtent If scrollDirection is ScrollDirection.vertical (the default) then itemExtent should be the height of each item; otherwise it should be the width of each item. Replaced _velocityForFlingGesture() in scrollable.dart with Scrollable._eventVelocity() The original version clamped pixels/ms against pixels/sec constants. The new version also deals with scrollDirection. - Plumbed scrollDirection though FixedHeightScrollable and ScrollableList Both classes should now support horizontal scrolling.
2015-08-17 23:48:13 +00:00
});
}
2015-09-24 22:31:06 +00:00
static const TextStyle cardLabelStyle =
TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold);
2015-09-24 22:31:06 +00:00
List<CardModel> cardModels;
2017-02-21 22:54:29 +00:00
Size pageSize = const Size(200.0, 200.0);
Axis scrollDirection = Axis.horizontal;
2015-09-24 22:31:06 +00:00
bool itemsWrap = false;
Widget buildCard(CardModel cardModel) {
final Widget card = Card(
Adds PageableList, other scrolling related changes and fixes - PageableList extends ScrollableList One fixed width or height item is visible and centered at a time. Fling and drag gestures scroll to the next/previous item. - Scrollable.scrollTo(), Scrollable.scrollBy(), ensureWidgetIsVisible() API changed The named animation parameter for these methods was replaced by duration and curve. All of the methods now return a Future. The Future completes when the scroll does. This change eliminates the need for Scrollable to temporarily take ownership of a ValueAnimation object (see #645). - Using Future.then() instead of an AnimationPerformance status listener In ensure_visible.dart _handleTap() uses ensureWidgetIsVisible() to center the card roughly as before and then. When the implicit scroll animation is complete, it changes the centered card's label font. The change is made when the Future returned by ensureWidgetIsVisible() completes. - FixedHeightScrollable's itemHeight parameter is now itemExtent If scrollDirection is ScrollDirection.vertical (the default) then itemExtent should be the height of each item; otherwise it should be the width of each item. Replaced _velocityForFlingGesture() in scrollable.dart with Scrollable._eventVelocity() The original version clamped pixels/ms against pixels/sec constants. The new version also deals with scrollDirection. - Plumbed scrollDirection though FixedHeightScrollable and ScrollableList Both classes should now support horizontal scrolling.
2015-08-17 23:48:13 +00:00
color: cardModel.color,
child: Container(
Adds PageableList, other scrolling related changes and fixes - PageableList extends ScrollableList One fixed width or height item is visible and centered at a time. Fling and drag gestures scroll to the next/previous item. - Scrollable.scrollTo(), Scrollable.scrollBy(), ensureWidgetIsVisible() API changed The named animation parameter for these methods was replaced by duration and curve. All of the methods now return a Future. The Future completes when the scroll does. This change eliminates the need for Scrollable to temporarily take ownership of a ValueAnimation object (see #645). - Using Future.then() instead of an AnimationPerformance status listener In ensure_visible.dart _handleTap() uses ensureWidgetIsVisible() to center the card roughly as before and then. When the implicit scroll animation is complete, it changes the centered card's label font. The change is made when the Future returned by ensureWidgetIsVisible() completes. - FixedHeightScrollable's itemHeight parameter is now itemExtent If scrollDirection is ScrollDirection.vertical (the default) then itemExtent should be the height of each item; otherwise it should be the width of each item. Replaced _velocityForFlingGesture() in scrollable.dart with Scrollable._eventVelocity() The original version clamped pixels/ms against pixels/sec constants. The new version also deals with scrollDirection. - Plumbed scrollDirection though FixedHeightScrollable and ScrollableList Both classes should now support horizontal scrolling.
2015-08-17 23:48:13 +00:00
width: cardModel.size.width,
height: cardModel.size.height,
padding: const EdgeInsets.all(8.0),
child: Center(child: Text(cardModel.label, style: cardLabelStyle)),
),
Adds PageableList, other scrolling related changes and fixes - PageableList extends ScrollableList One fixed width or height item is visible and centered at a time. Fling and drag gestures scroll to the next/previous item. - Scrollable.scrollTo(), Scrollable.scrollBy(), ensureWidgetIsVisible() API changed The named animation parameter for these methods was replaced by duration and curve. All of the methods now return a Future. The Future completes when the scroll does. This change eliminates the need for Scrollable to temporarily take ownership of a ValueAnimation object (see #645). - Using Future.then() instead of an AnimationPerformance status listener In ensure_visible.dart _handleTap() uses ensureWidgetIsVisible() to center the card roughly as before and then. When the implicit scroll animation is complete, it changes the centered card's label font. The change is made when the Future returned by ensureWidgetIsVisible() completes. - FixedHeightScrollable's itemHeight parameter is now itemExtent If scrollDirection is ScrollDirection.vertical (the default) then itemExtent should be the height of each item; otherwise it should be the width of each item. Replaced _velocityForFlingGesture() in scrollable.dart with Scrollable._eventVelocity() The original version clamped pixels/ms against pixels/sec constants. The new version also deals with scrollDirection. - Plumbed scrollDirection though FixedHeightScrollable and ScrollableList Both classes should now support horizontal scrolling.
2015-08-17 23:48:13 +00:00
);
final BoxConstraints constraints = (scrollDirection == Axis.vertical)
? BoxConstraints.tightFor(height: pageSize.height)
: BoxConstraints.tightFor(width: pageSize.width);
return Container(
Adds PageableList, other scrolling related changes and fixes - PageableList extends ScrollableList One fixed width or height item is visible and centered at a time. Fling and drag gestures scroll to the next/previous item. - Scrollable.scrollTo(), Scrollable.scrollBy(), ensureWidgetIsVisible() API changed The named animation parameter for these methods was replaced by duration and curve. All of the methods now return a Future. The Future completes when the scroll does. This change eliminates the need for Scrollable to temporarily take ownership of a ValueAnimation object (see #645). - Using Future.then() instead of an AnimationPerformance status listener In ensure_visible.dart _handleTap() uses ensureWidgetIsVisible() to center the card roughly as before and then. When the implicit scroll animation is complete, it changes the centered card's label font. The change is made when the Future returned by ensureWidgetIsVisible() completes. - FixedHeightScrollable's itemHeight parameter is now itemExtent If scrollDirection is ScrollDirection.vertical (the default) then itemExtent should be the height of each item; otherwise it should be the width of each item. Replaced _velocityForFlingGesture() in scrollable.dart with Scrollable._eventVelocity() The original version clamped pixels/ms against pixels/sec constants. The new version also deals with scrollDirection. - Plumbed scrollDirection though FixedHeightScrollable and ScrollableList Both classes should now support horizontal scrolling.
2015-08-17 23:48:13 +00:00
key: cardModel.key,
constraints: constraints,
child: Center(child: card),
Adds PageableList, other scrolling related changes and fixes - PageableList extends ScrollableList One fixed width or height item is visible and centered at a time. Fling and drag gestures scroll to the next/previous item. - Scrollable.scrollTo(), Scrollable.scrollBy(), ensureWidgetIsVisible() API changed The named animation parameter for these methods was replaced by duration and curve. All of the methods now return a Future. The Future completes when the scroll does. This change eliminates the need for Scrollable to temporarily take ownership of a ValueAnimation object (see #645). - Using Future.then() instead of an AnimationPerformance status listener In ensure_visible.dart _handleTap() uses ensureWidgetIsVisible() to center the card roughly as before and then. When the implicit scroll animation is complete, it changes the centered card's label font. The change is made when the Future returned by ensureWidgetIsVisible() completes. - FixedHeightScrollable's itemHeight parameter is now itemExtent If scrollDirection is ScrollDirection.vertical (the default) then itemExtent should be the height of each item; otherwise it should be the width of each item. Replaced _velocityForFlingGesture() in scrollable.dart with Scrollable._eventVelocity() The original version clamped pixels/ms against pixels/sec constants. The new version also deals with scrollDirection. - Plumbed scrollDirection though FixedHeightScrollable and ScrollableList Both classes should now support horizontal scrolling.
2015-08-17 23:48:13 +00:00
);
}
void switchScrollDirection() {
setState(() {
scrollDirection = (scrollDirection == Axis.vertical)
? Axis.horizontal
: Axis.vertical;
});
}
void toggleItemsWrap() {
setState(() {
itemsWrap = !itemsWrap;
});
}
Widget _buildDrawer() {
return Drawer(
child: ListView(
children: <Widget>[
const DrawerHeader(child: Center(child: Text('Options'))),
ListTile(
leading: const Icon(Icons.more_horiz),
selected: scrollDirection == Axis.horizontal,
trailing: const Text('Horizontal Layout'),
onTap: switchScrollDirection,
),
ListTile(
leading: const Icon(Icons.more_vert),
selected: scrollDirection == Axis.vertical,
trailing: const Text('Vertical Layout'),
onTap: switchScrollDirection,
),
ListTile(
onTap: toggleItemsWrap,
title: const Text('Scrolling wraps around'),
// TODO(abarth): Actually make this checkbox change this value.
trailing: Checkbox(value: itemsWrap, onChanged: null),
),
],
),
);
}
2019-12-05 21:34:06 +00:00
AppBar _buildAppBar() {
return AppBar(
title: const Text('PageView'),
actions: <Widget>[
Text(scrollDirection == Axis.horizontal ? 'horizontal' : 'vertical'),
],
);
}
Widget _buildBody(BuildContext context) {
return PageView(
children: cardModels.map<Widget>(buildCard).toList(),
// TODO(abarth): itemsWrap: itemsWrap,
scrollDirection: scrollDirection,
);
}
Adds PageableList, other scrolling related changes and fixes - PageableList extends ScrollableList One fixed width or height item is visible and centered at a time. Fling and drag gestures scroll to the next/previous item. - Scrollable.scrollTo(), Scrollable.scrollBy(), ensureWidgetIsVisible() API changed The named animation parameter for these methods was replaced by duration and curve. All of the methods now return a Future. The Future completes when the scroll does. This change eliminates the need for Scrollable to temporarily take ownership of a ValueAnimation object (see #645). - Using Future.then() instead of an AnimationPerformance status listener In ensure_visible.dart _handleTap() uses ensureWidgetIsVisible() to center the card roughly as before and then. When the implicit scroll animation is complete, it changes the centered card's label font. The change is made when the Future returned by ensureWidgetIsVisible() completes. - FixedHeightScrollable's itemHeight parameter is now itemExtent If scrollDirection is ScrollDirection.vertical (the default) then itemExtent should be the height of each item; otherwise it should be the width of each item. Replaced _velocityForFlingGesture() in scrollable.dart with Scrollable._eventVelocity() The original version clamped pixels/ms against pixels/sec constants. The new version also deals with scrollDirection. - Plumbed scrollDirection though FixedHeightScrollable and ScrollableList Both classes should now support horizontal scrolling.
2015-08-17 23:48:13 +00:00
@override
2015-09-24 22:31:06 +00:00
Widget build(BuildContext context) {
return IconTheme(
data: const IconThemeData(color: Colors.white),
child: Scaffold(
appBar: _buildAppBar(),
drawer: _buildDrawer(),
body: _buildBody(context),
),
Adds PageableList, other scrolling related changes and fixes - PageableList extends ScrollableList One fixed width or height item is visible and centered at a time. Fling and drag gestures scroll to the next/previous item. - Scrollable.scrollTo(), Scrollable.scrollBy(), ensureWidgetIsVisible() API changed The named animation parameter for these methods was replaced by duration and curve. All of the methods now return a Future. The Future completes when the scroll does. This change eliminates the need for Scrollable to temporarily take ownership of a ValueAnimation object (see #645). - Using Future.then() instead of an AnimationPerformance status listener In ensure_visible.dart _handleTap() uses ensureWidgetIsVisible() to center the card roughly as before and then. When the implicit scroll animation is complete, it changes the centered card's label font. The change is made when the Future returned by ensureWidgetIsVisible() completes. - FixedHeightScrollable's itemHeight parameter is now itemExtent If scrollDirection is ScrollDirection.vertical (the default) then itemExtent should be the height of each item; otherwise it should be the width of each item. Replaced _velocityForFlingGesture() in scrollable.dart with Scrollable._eventVelocity() The original version clamped pixels/ms against pixels/sec constants. The new version also deals with scrollDirection. - Plumbed scrollDirection though FixedHeightScrollable and ScrollableList Both classes should now support horizontal scrolling.
2015-08-17 23:48:13 +00:00
);
}
}
void main() {
runApp(MaterialApp(
title: 'PageView',
theme: ThemeData(
brightness: Brightness.light,
primarySwatch: Colors.blue,
accentColor: Colors.redAccent,
),
home: PageViewApp(),
));
Adds PageableList, other scrolling related changes and fixes - PageableList extends ScrollableList One fixed width or height item is visible and centered at a time. Fling and drag gestures scroll to the next/previous item. - Scrollable.scrollTo(), Scrollable.scrollBy(), ensureWidgetIsVisible() API changed The named animation parameter for these methods was replaced by duration and curve. All of the methods now return a Future. The Future completes when the scroll does. This change eliminates the need for Scrollable to temporarily take ownership of a ValueAnimation object (see #645). - Using Future.then() instead of an AnimationPerformance status listener In ensure_visible.dart _handleTap() uses ensureWidgetIsVisible() to center the card roughly as before and then. When the implicit scroll animation is complete, it changes the centered card's label font. The change is made when the Future returned by ensureWidgetIsVisible() completes. - FixedHeightScrollable's itemHeight parameter is now itemExtent If scrollDirection is ScrollDirection.vertical (the default) then itemExtent should be the height of each item; otherwise it should be the width of each item. Replaced _velocityForFlingGesture() in scrollable.dart with Scrollable._eventVelocity() The original version clamped pixels/ms against pixels/sec constants. The new version also deals with scrollDirection. - Plumbed scrollDirection though FixedHeightScrollable and ScrollableList Both classes should now support horizontal scrolling.
2015-08-17 23:48:13 +00:00
}