TwoDimensional scrolling foundation (#125437)

From the 2D scrolling proposal: [flutter.dev/go/2D-Foundation](https://flutter.dev/go/2D-Foundation) ✅  updated 4/25

Fixes https://github.com/flutter/flutter/issues/125505

Follow up issues:
- https://github.com/flutter/flutter/issues/126297
- https://github.com/flutter/flutter/issues/126298
- https://github.com/flutter/flutter/issues/126299
-  https://github.com/flutter/flutter/issues/122348

This adds a mostly abstract foundation for 2D scrolling in Flutter.

With these base classes, developers will be able to construct widgets that scroll in both dimensions and can lazily load their children for the best performance. This implementation is meant to be flexible in order to support different kinds of 2D compositions, from tables to scatter plots. 

The upcoming TableView, TreeView, etc widgets (coming soon in flutter/packages) are built on top of this foundation.
This commit is contained in:
Kate Lovett
2023-05-26 17:22:21 -05:00
committed by GitHub
parent 15fa5b53d8
commit 0f1a95d19e
11 changed files with 5224 additions and 9 deletions

View File

@@ -9,6 +9,7 @@ import 'automatic_keep_alive.dart';
import 'basic.dart';
import 'framework.dart';
import 'selection_container.dart';
import 'two_dimensional_viewport.dart';
export 'package:flutter/rendering.dart' show
SliverGridDelegate,
@@ -630,7 +631,7 @@ class SliverChildListDelegate extends SliverChildDelegate {
/// [children] such as `someWidget.children.add(...)` or
/// passing a reference of the original list value to the [children] parameter
/// will result in incorrect behaviors. Whenever the
/// children list is modified, a new list object should be provided.
/// children list is modified, a new list object must be provided.
///
/// The following code corrects the problem mentioned above.
///
@@ -861,3 +862,272 @@ Widget _createErrorWidget(Object exception, StackTrace stackTrace) {
FlutterError.reportError(details);
return ErrorWidget.builder(details);
}
// TODO(Piinks): Come back and add keep alive support, https://github.com/flutter/flutter/issues/126297
/// A delegate that supplies children for scrolling in two dimensions.
///
/// A [TwoDimensionalScrollView] lazily constructs its box children to avoid
/// creating more children than are visible through the
/// [TwoDimensionalViewport]. Rather than receiving children as an
/// explicit [List], it receives its children using a
/// [TwoDimensionalChildDelegate].
///
/// As a ChangeNotifier, this delegate allows subclasses to notify its listeners
/// (typically as a subclass of [RenderTwoDimensionalViewport]) to rebuild when
/// aspects of the delegate change. When values returned by getters or builders
/// on this delegate change, [notifyListeners] should be called. This signals to
/// the [RenderTwoDimensionalViewport] that the getters and builders need to be
/// re-queried to update the layout of children in the viewport.
///
/// See also:
///
/// * [TwoDimensionalChildBuilderDelegate], an concrete subclass of this that
/// lazily builds children on demand.
/// * [TwoDimensionalChildListDelegate], an concrete subclass of this that
/// uses a two dimensional array to layout children.
abstract class TwoDimensionalChildDelegate extends ChangeNotifier {
/// Returns the child with the given [ChildVicinity], which is described in
/// terms of x and y indices.
///
/// Subclasses must implement this function and will typically wrap their
/// children in [RepaintBoundary] widgets.
///
/// The values returned by this method are cached. To indicate that the
/// widgets have changed, a new delegate must be provided, and the new
/// delegate's [shouldRebuild] method must return true. Alternatively,
/// calling [notifyListeners] will allow the same delegate to be used.
Widget? build(BuildContext context, ChildVicinity vicinity);
/// Called whenever a new instance of the child delegate class is
/// provided.
///
/// If the new instance represents different information than the old
/// instance, then the method should return true, otherwise it should return
/// false.
///
/// If the method returns false, then the [build] call might be optimized
/// away.
bool shouldRebuild(covariant TwoDimensionalChildDelegate oldDelegate);
}
/// A delegate that supplies children for a [TwoDimensionalScrollView] using a
/// builder callback.
///
/// The widgets returned from the builder callback are automatically wrapped in
/// [RepaintBoundary] widgets if [addRepaintBoundaries] is true
/// (also the default).
///
/// See also:
///
/// * [TwoDimensionalChildListDelegate], which is a similar delegate that has an
/// explicit two dimensional array of children.
/// * [SliverChildBuilderDelegate], which is a delegate that uses a builder
/// callback to construct the children in one dimension instead of two.
/// * [SliverChildListDelegate], which is a delegate that has an explicit list
/// of children in one dimension instead of two.
class TwoDimensionalChildBuilderDelegate extends TwoDimensionalChildDelegate {
/// Creates a delegate that supplies children for a [TwoDimensionalScrollView]
/// using the given builder callback.
TwoDimensionalChildBuilderDelegate({
this.addRepaintBoundaries = true,
required this.builder,
int? maxXIndex,
int? maxYIndex,
}) : _maxYIndex = maxYIndex,
_maxXIndex = maxXIndex;
/// Called to build children on demand.
///
/// Implementors of [RenderTwoDimensionalViewport.layoutChildSequence]
/// call this builder to create the children of the viewport. For
/// [ChildVicinity] indices greater than [maxXIndex] or [maxYIndex], null will
/// be returned by the default [build] implementation. This default behavior
/// can be changed by overriding the build method.
///
/// Must return null if asked to build a widget with a [ChildVicinity] that
/// does not exist.
///
/// The delegate wraps the children returned by this builder in
/// [RepaintBoundary] widgets if [addRepaintBoundaries] is true.
final TwoDimensionalIndexedWidgetBuilder builder;
/// The maximum [ChildVicinity.xIndex] for children in the x axis.
///
/// {@template flutter.widgets.twoDimensionalChildBuilderDelegate.maxIndex}
/// For each [ChildVicinity], the child's relative location is described in
/// terms of x and y indices to facilitate a consistent visitor pattern for
/// all children in the viewport.
///
/// This is fairly straightforward in the context of a table implementation,
/// where there is usually the same number of columns in every row and vice
/// versa, each aligned one after the other.
///
/// When plotting children more abstractly in two dimensional space, there may
/// be more x indices for a given y index than another y index. An example of
/// this would be a scatter plot where there are more children at the top of
/// the graph than at the bottom.
///
/// If null, subclasses of [RenderTwoDimensionalViewport] can continue call on
/// the [builder] until null has been returned for each known index of x and
/// y. In some cases, null may not be a terminating result, such as a table
/// with a merged cell spanning multiple indices. Refer to the
/// [TwoDimensionalViewport] subclass to learn how this value is applied in
/// the specific use case.
///
/// If the value changes, the delegate will call [notifyListeners]. This
/// informs the [RenderTwoDimensionalViewport] that any cached information
/// from the delegate is invalid.
/// {@endtemplate}
///
/// This value represents the greatest x index of all [ChildVicinity]s for the
/// two dimensional scroll view.
///
/// See also:
///
/// * [RenderTwoDimensionalViewport.buildOrObtainChildFor], the method that
/// leads to calling on the delegate to build a child of the given
/// [ChildVicinity].
int? get maxXIndex => _maxXIndex;
int? _maxXIndex;
set maxXIndex(int? value) {
if (value == maxXIndex) {
return;
}
_maxXIndex = value;
notifyListeners();
}
/// The maximum [ChildVicinity.yIndex] for children in the y axis.
///
/// {@macro flutter.widgets.twoDimensionalChildBuilderDelegate.maxIndex}
///
/// This value represents the greatest y index of all [ChildVicinity]s for the
/// two dimensional scroll view.
///
/// See also:
///
/// * [RenderTwoDimensionalViewport.buildOrObtainChildFor], the method that
/// leads to calling on the delegate to build a child of the given
/// [ChildVicinity].
int? get maxYIndex => _maxYIndex;
int? _maxYIndex;
set maxYIndex(int? value) {
if (maxYIndex == value) {
return;
}
_maxYIndex = value;
notifyListeners();
}
/// {@macro flutter.widgets.SliverChildBuilderDelegate.addRepaintBoundaries}
final bool addRepaintBoundaries;
@override
Widget? build(BuildContext context, ChildVicinity vicinity) {
// If we have exceeded explicit upper bounds, return null.
if (vicinity.xIndex < 0 || (maxXIndex != null && vicinity.xIndex > maxXIndex!)) {
return null;
}
if (vicinity.yIndex < 0 || (maxYIndex != null && vicinity.yIndex > maxYIndex!)) {
return null;
}
Widget? child;
try {
child = builder(context, vicinity);
} catch (exception, stackTrace) {
child = _createErrorWidget(exception, stackTrace);
}
if (child == null) {
return null;
}
if (addRepaintBoundaries) {
child = RepaintBoundary(child: child);
}
return child;
}
@override
bool shouldRebuild(covariant TwoDimensionalChildDelegate oldDelegate) => true;
}
/// A delegate that supplies children for a [TwoDimensionalViewport] using an
/// explicit two dimensional array.
///
/// In general, building all the widgets in advance is not efficient. It is
/// better to create a delegate that builds them on demand using
/// [TwoDimensionalChildBuilderDelegate] or by subclassing
/// [TwoDimensionalChildDelegate] directly.
///
/// This class is provided for the cases where either the list of children is
/// known well in advance (ideally the children are themselves compile-time
/// constants, for example), and therefore will not be built each time the
/// delegate itself is created, or the array is small, such that it's likely
/// always visible (and thus there is nothing to be gained by building it on
/// demand).
///
/// The widgets in the given [children] list are automatically wrapped in
/// [RepaintBoundary] widgets if [addRepaintBoundaries] is true
/// (also the default).
///
/// The [children] are accessed for each [ChildVicinity.yIndex] and
/// [ChildVicinity.xIndex] of the [TwoDimensionalViewport] as
/// `children[vicinity.yIndex][vicinity.xIndex]`.
///
/// See also:
///
/// * [TwoDimensionalChildBuilderDelegate], which is a delegate that uses a
/// builder callback to construct the children.
/// * [SliverChildBuilderDelegate], which is a delegate that uses a builder
/// callback to construct the children in one dimension instead of two.
/// * [SliverChildListDelegate], which is a delegate that has an explicit list
/// of children in one dimension instead of two.
class TwoDimensionalChildListDelegate extends TwoDimensionalChildDelegate {
/// Creates a delegate that supplies children for a [TwoDimensionalScrollView].
///
/// The [children] and [addRepaintBoundaries] must not be
/// null.
TwoDimensionalChildListDelegate({
this.addRepaintBoundaries = true,
required this.children,
});
/// The widgets to display.
///
/// Also, a [Widget] in Flutter is immutable, so directly modifying the
/// [children] such as `someWidget.children.add(...)` or
/// passing a reference of the original list value to the [children] parameter
/// will result in incorrect behaviors. Whenever the
/// children list is modified, a new list object must be provided.
///
/// The [children] are accessed for each [ChildVicinity.yIndex] and
/// [ChildVicinity.xIndex] of the [TwoDimensionalViewport] as
/// `children[vicinity.yIndex][vicinity.xIndex]`.
final List<List<Widget>> children;
/// {@macro flutter.widgets.SliverChildBuilderDelegate.addRepaintBoundaries}
final bool addRepaintBoundaries;
@override
Widget? build(BuildContext context, ChildVicinity vicinity) {
// If we have exceeded explicit upper bounds, return null.
if (vicinity.yIndex < 0 || vicinity.yIndex >= children.length) {
return null;
}
if (vicinity.xIndex < 0 || vicinity.xIndex >= children[vicinity.yIndex].length) {
return null;
}
Widget child = children[vicinity.yIndex][vicinity.xIndex];
if (addRepaintBoundaries) {
child = RepaintBoundary(child: child);
}
return child;
}
@override
bool shouldRebuild(covariant TwoDimensionalChildListDelegate oldDelegate) {
return children != oldDelegate.children;
}
}

View File

@@ -21,6 +21,7 @@ import 'scroll_delegate.dart';
import 'scroll_notification.dart';
import 'scroll_physics.dart';
import 'scrollable.dart';
import 'scrollable_helpers.dart';
import 'sliver.dart';
import 'sliver_prototype_extent_list.dart';
import 'viewport.dart';
@@ -39,7 +40,8 @@ enum ScrollViewKeyboardDismissBehavior {
onDrag,
}
/// A widget that scrolls.
/// A widget that combines a [Scrollable] and a [Viewport] to create an
/// interactive scrolling pane of content in one dimension.
///
/// Scrollable widgets consist of three pieces:
///
@@ -71,6 +73,8 @@ enum ScrollViewKeyboardDismissBehavior {
/// effects using slivers.
/// * [ScrollNotification] and [NotificationListener], which can be used to watch
/// the scroll position without using a [ScrollController].
/// * [TwoDimensionalScrollView], which is a similar widget [ScrollView] that
/// scrolls in two dimensions.
abstract class ScrollView extends StatelessWidget {
/// Creates a widget that scrolls.
///
@@ -1769,7 +1773,7 @@ class ListView extends BoxScrollView {
/// {@end-tool}
///
/// By default, [GridView] will automatically pad the limits of the
/// grids's scrollable to avoid partial obstructions indicated by
/// grid's scrollable to avoid partial obstructions indicated by
/// [MediaQuery]'s padding. To avoid this behavior, override with a
/// zero [padding] property.
///

View File

@@ -40,7 +40,12 @@ export 'package:flutter/physics.dart' show Tolerance;
/// scrollable content is displayed.
typedef ViewportBuilder = Widget Function(BuildContext context, ViewportOffset position);
/// A widget that scrolls.
/// Signature used by [TwoDimensionalScrollable] to build the viewport through
/// which the scrollable content is displayed.
typedef TwoDimensionalViewportBuilder = Widget Function(BuildContext context, ViewportOffset verticalPosition, ViewportOffset horizontalPosition);
/// A widget that manages scrolling in one dimension and informs the [Viewport]
/// through which the content is viewed.
///
/// [Scrollable] implements the interaction model for a scrollable widget,
/// including gesture recognition, but does not have an opinion about how the
@@ -177,6 +182,7 @@ class Scrollable extends StatefulWidget {
/// slivers and sizes itself based on the size of the slivers.
final ViewportBuilder viewportBuilder;
/// {@template flutter.widgets.Scrollable.incrementCalculator}
/// An optional function that will be called to calculate the distance to
/// scroll when the scrollable is asked to scroll via the keyboard using a
/// [ScrollAction].
@@ -188,14 +194,17 @@ class Scrollable extends StatefulWidget {
/// If [incrementCalculator] is null, the default for
/// [ScrollIncrementType.page] is 80% of the size of the scroll window, and
/// for [ScrollIncrementType.line], 50 logical pixels.
/// {@endtemplate}
final ScrollIncrementCalculator? incrementCalculator;
/// {@template flutter.widgets.scrollable.excludeFromSemantics}
/// Whether the scroll actions introduced by this [Scrollable] are exposed
/// in the semantics tree.
///
/// Text fields with an overflow are usually scrollable to make sure that the
/// user can get to the beginning/end of the entered text. However, these
/// scrolling actions are generally not exposed to the semantics layer.
/// {@endtemplate}
///
/// See also:
///
@@ -1611,3 +1620,690 @@ class _RestorableScrollOffset extends RestorableValue<double?> {
@override
bool get enabled => value != null;
}
// 2D SCROLLING
/// Specifies how to configure the [DragGestureRecognizer]s of a
/// [TwoDimensionalScrollable].
// TODO(Piinks): Add sample code, https://github.com/flutter/flutter/issues/126298
enum DiagonalDragBehavior {
/// This behavior will not allow for any diagonal scrolling.
///
/// Drag gestures in one direction or the other will lock the input axis until
/// the gesture is released.
none,
/// This behavior will only allow diagonal scrolling on a weighted
/// scale per gesture event.
///
/// This means that after initially evaluating the drag gesture, the weighted
/// evaluation (based on [kTouchSlop]) stands until the gesture is released.
weightedEvent,
/// This behavior will only allow diagonal scrolling on a weighted
/// scale that is evaluated throughout a gesture event.
///
/// This means that during each update to the drag gesture, the scrolling
/// axis will be allowed to scroll diagonally if it exceeds the
/// [kTouchSlop].
weightedContinuous,
/// This behavior allows free movement in any and all directions when
/// dragging.
free,
}
/// A widget that manages scrolling in both the vertical and horizontal
/// dimensions and informs the [TwoDimensionalViewport] through which the
/// content is viewed.
///
/// [TwoDimensionalScrollable] implements the interaction model for a scrollable
/// widget in both the vertical and horizontal axes, including gesture
/// recognition, but does not have an opinion about how the
/// [TwoDimensionalViewport], which actually displays the children, is
/// constructed.
///
/// It's rare to construct a [TwoDimensionalScrollable] directly. Instead,
/// consider subclassing [TwoDimensionalScrollView], which combines scrolling,
/// viewporting, and a layout model in both dimensions.
///
/// See also:
///
/// * [TwoDimensionalScrollView], an abstract base class for displaying a
/// scrolling array of children in both directions.
/// * [TwoDimensionalViewport], which can be used to customize the child layout
/// model.
class TwoDimensionalScrollable extends StatefulWidget {
/// Creates a widget that scrolls in two dimensions.
///
/// The [horizontalDetails], [verticalDetails], and [viewportBuilder] must not
/// be null.
const TwoDimensionalScrollable({
super.key,
required this.horizontalDetails,
required this.verticalDetails,
required this.viewportBuilder,
this.incrementCalculator,
this.restorationId,
this.excludeFromSemantics = false,
this.diagonalDragBehavior = DiagonalDragBehavior.none,
this.dragStartBehavior = DragStartBehavior.start,
});
/// How scrolling gestures should lock to one axis, or allow free movement
/// in both axes.
final DiagonalDragBehavior diagonalDragBehavior;
/// The configuration of the horizontal [Scrollable].
///
/// These [ScrollableDetails] can be used to set the [AxisDirection],
/// [ScrollController], [ScrollPhysics] and more for the horizontal axis.
final ScrollableDetails horizontalDetails;
/// The configuration of the vertical [Scrollable].
///
/// These [ScrollableDetails] can be used to set the [AxisDirection],
/// [ScrollController], [ScrollPhysics] and more for the vertical axis.
final ScrollableDetails verticalDetails;
/// Builds the viewport through which the scrollable content is displayed.
///
/// A [TwoDimensionalViewport] uses two given [ViewportOffset]s to determine
/// which part of its content is actually visible through the viewport.
///
/// See also:
///
/// * [TwoDimensionalViewport], which is a viewport that displays a span of
/// widgets in both dimensions.
final TwoDimensionalViewportBuilder viewportBuilder;
/// {@macro flutter.widgets.Scrollable.incrementCalculator}
///
/// This value applies in both axes.
final ScrollIncrementCalculator? incrementCalculator;
/// {@macro flutter.widgets.scrollable.restorationId}
///
/// Internally, the [TwoDimensionalScrollable] will introduce a
/// [RestorationScope] that will be assigned this value. The two [Scrollable]s
/// within will then be given unique IDs within this scope.
final String? restorationId;
/// {@macro flutter.widgets.scrollable.excludeFromSemantics}
///
/// This value applies to both axes.
final bool excludeFromSemantics;
/// {@macro flutter.widgets.scrollable.dragStartBehavior}
///
/// This value applies in both axes.
final DragStartBehavior dragStartBehavior;
@override
State<TwoDimensionalScrollable> createState() => TwoDimensionalScrollableState();
/// The state from the closest instance of this class that encloses the given
/// context, or null if none is found.
///
/// Typical usage is as follows:
///
/// ```dart
/// TwoDimensionalScrollableState? scrollable = TwoDimensionalScrollable.maybeOf(context);
/// ```
///
/// Calling this method will create a dependency on the closest
/// [TwoDimensionalScrollable] in the [context]. The internal [Scrollable]s
/// can be accessed through [TwoDimensionalScrollableState.verticalScrollable]
/// and [TwoDimensionalScrollableState.horizontalScrollable].
///
/// Alternatively, [Scrollable.maybeOf] can be used by providing the desired
/// [Axis] to the `axis` parameter.
///
/// See also:
///
/// * [TwoDimensionalScrollable.of], which is similar to this method, but
/// asserts if no [Scrollable] ancestor is found.
static TwoDimensionalScrollableState? maybeOf(BuildContext context) {
final _TwoDimensionalScrollableScope? widget = context.dependOnInheritedWidgetOfExactType<_TwoDimensionalScrollableScope>();
return widget?.twoDimensionalScrollable;
}
/// The state from the closest instance of this class that encloses the given
/// context.
///
/// Typical usage is as follows:
///
/// ```dart
/// TwoDimensionalScrollableState scrollable = TwoDimensionalScrollable.of(context);
/// ```
///
/// Calling this method will create a dependency on the closest
/// [TwoDimensionalScrollable] in the [context]. The internal [Scrollable]s
/// can be accessed through [TwoDimensionalScrollableState.verticalScrollable]
/// and [TwoDimensionalScrollableState.horizontalScrollable].
///
/// If no [TwoDimensionalScrollable] ancestor is found, then this method will
/// assert in debug mode, and throw an exception in release mode.
///
/// Alternatively, [Scrollable.of] can be used by providing the desired [Axis]
/// to the `axis` parameter.
///
/// See also:
///
/// * [TwoDimensionalScrollable.maybeOf], which is similar to this method,
/// but returns null if no [TwoDimensionalScrollable] ancestor is found.
static TwoDimensionalScrollableState of(BuildContext context) {
final TwoDimensionalScrollableState? scrollableState = maybeOf(context);
assert(() {
if (scrollableState == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary(
'TwoDimensionalScrollable.of() was called with a context that does '
'not contain a TwoDimensionalScrollable widget.\n'
),
ErrorDescription(
'No TwoDimensionalScrollable widget ancestor could be found starting '
'from the context that was passed to TwoDimensionalScrollable.of(). '
'This can happen because you are using a widget that looks for a '
'TwoDimensionalScrollable ancestor, but no such ancestor exists.\n'
'The context used was:\n'
' $context',
),
]);
}
return true;
}());
return scrollableState!;
}
}
/// State object for a [TwoDimensionalScrollable] widget.
///
/// To manipulate one of the internal [Scrollable] widget's scroll position, use
/// the object obtained from the [verticalScrollable] or [horizontalScrollable]
/// property.
///
/// To be informed of when a [TwoDimensionalScrollable] widget is scrolling,
/// use a [NotificationListener] to listen for [ScrollNotification]s.
/// Both axes will have the same viewport depth since there is only one
/// viewport, and so should be differentiated by the [Axis] of the
/// [ScrollMetrics] provided by the notification.
class TwoDimensionalScrollableState extends State<TwoDimensionalScrollable> {
ScrollController? _verticalFallbackController;
ScrollController? _horizontalFallbackController;
final GlobalKey<ScrollableState> _verticalOuterScrollableKey = GlobalKey<ScrollableState>();
final GlobalKey<ScrollableState> _horizontalInnerScrollableKey = GlobalKey<ScrollableState>();
/// The [ScrollableState] of the vertical axis.
///
/// Accessible by calling [TwoDimensionalScrollable.of].
///
/// Alternatively, [Scrollable.of] can be used by providing [Axis.vertical]
/// to the `axis` parameter.
ScrollableState get verticalScrollable {
assert(_verticalOuterScrollableKey.currentState != null);
return _verticalOuterScrollableKey.currentState!;
}
/// The [ScrollableState] of the horizontal axis.
///
/// Accessible by calling [TwoDimensionalScrollable.of].
///
/// Alternatively, [Scrollable.of] can be used by providing [Axis.horizontal]
/// to the `axis` parameter.
ScrollableState get horizontalScrollable {
assert(_horizontalInnerScrollableKey.currentState != null);
return _horizontalInnerScrollableKey.currentState!;
}
@override
void initState() {
if (widget.verticalDetails.controller == null) {
_verticalFallbackController = ScrollController();
}
if (widget.horizontalDetails.controller == null) {
_horizontalFallbackController = ScrollController();
}
super.initState();
}
@override
void didUpdateWidget(TwoDimensionalScrollable oldWidget) {
super.didUpdateWidget(oldWidget);
// Handle changes in the provided/fallback scroll controllers
// Vertical
if (oldWidget.verticalDetails.controller != widget.verticalDetails.controller) {
if (oldWidget.verticalDetails.controller == null) {
// The old controller was null, meaning the fallback cannot be null.
// Dispose of the fallback.
assert(_verticalFallbackController != null);
assert(widget.verticalDetails.controller != null);
_verticalFallbackController!.dispose();
_verticalFallbackController = null;
} else if (widget.verticalDetails.controller == null) {
// If the new controller is null, we need to set up the fallback
// ScrollController.
assert(_verticalFallbackController == null);
_verticalFallbackController = ScrollController();
}
}
// Horizontal
if (oldWidget.horizontalDetails.controller != widget.horizontalDetails.controller) {
if (oldWidget.horizontalDetails.controller == null) {
// The old controller was null, meaning the fallback cannot be null.
// Dispose of the fallback.
assert(_horizontalFallbackController != null);
assert(widget.horizontalDetails.controller != null);
_horizontalFallbackController!.dispose();
_horizontalFallbackController = null;
} else if (widget.horizontalDetails.controller == null) {
// If the new controller is null, we need to set up the fallback
// ScrollController.
assert(_horizontalFallbackController == null);
_horizontalFallbackController = ScrollController();
}
}
}
@override
Widget build(BuildContext context) {
assert(
axisDirectionToAxis(widget.verticalDetails.direction) == Axis.vertical,
'TwoDimensionalScrollable.verticalDetails are not Axis.vertical.'
);
assert(
axisDirectionToAxis(widget.horizontalDetails.direction) == Axis.horizontal,
'TwoDimensionalScrollable.horizontalDetails are not Axis.horizontal.'
);
final Widget result = RestorationScope(
restorationId: widget.restorationId,
child: _VerticalOuterDimension(
key: _verticalOuterScrollableKey,
axisDirection: widget.verticalDetails.direction,
controller: widget.verticalDetails.controller
?? _verticalFallbackController!,
physics: widget.verticalDetails.physics,
clipBehavior: widget.verticalDetails.clipBehavior
?? widget.verticalDetails.decorationClipBehavior
?? Clip.hardEdge,
incrementCalculator: widget.incrementCalculator,
excludeFromSemantics: widget.excludeFromSemantics,
restorationId: 'OuterVerticalTwoDimensionalScrollable',
dragStartBehavior: widget.dragStartBehavior,
diagonalDragBehavior: widget.diagonalDragBehavior,
viewportBuilder: (BuildContext context, ViewportOffset verticalOffset) {
return _HorizontalInnerDimension(
key: _horizontalInnerScrollableKey,
axisDirection: widget.horizontalDetails.direction,
controller: widget.horizontalDetails.controller
?? _horizontalFallbackController!,
physics: widget.horizontalDetails.physics,
clipBehavior: widget.horizontalDetails.clipBehavior
?? widget.horizontalDetails.decorationClipBehavior
?? Clip.hardEdge,
incrementCalculator: widget.incrementCalculator,
excludeFromSemantics: widget.excludeFromSemantics,
restorationId: 'InnerHorizontalTwoDimensionalScrollable',
dragStartBehavior: widget.dragStartBehavior,
diagonalDragBehavior: widget.diagonalDragBehavior,
viewportBuilder: (BuildContext context, ViewportOffset horizontalOffset) {
return widget.viewportBuilder(context, verticalOffset, horizontalOffset);
},
);
}
)
);
// TODO(Piinks): Build scrollbars for 2 dimensions instead of 1,
// https://github.com/flutter/flutter/issues/122348
return _TwoDimensionalScrollableScope(
twoDimensionalScrollable: this,
child: result,
);
}
@override
void dispose() {
_verticalFallbackController?.dispose();
_horizontalFallbackController?.dispose();
super.dispose();
}
}
// Enable TwoDimensionalScrollable.of() to work as if
// TwoDimensionalScrollableState was an inherited widget.
// TwoDimensionalScrollableState.build() always rebuilds its
// _TwoDimensionalScrollableScope.
class _TwoDimensionalScrollableScope extends InheritedWidget {
const _TwoDimensionalScrollableScope({
required this.twoDimensionalScrollable,
required super.child,
});
final TwoDimensionalScrollableState twoDimensionalScrollable;
@override
bool updateShouldNotify(_TwoDimensionalScrollableScope old) => false;
}
// Vertical outer scrollable of 2D scrolling
class _VerticalOuterDimension extends Scrollable {
const _VerticalOuterDimension({
super.key,
required super.viewportBuilder,
required super.axisDirection,
super.controller,
super.physics,
super.clipBehavior,
super.incrementCalculator,
super.excludeFromSemantics,
super.dragStartBehavior,
super.restorationId,
this.diagonalDragBehavior = DiagonalDragBehavior.none,
}) : assert(axisDirection == AxisDirection.up || axisDirection == AxisDirection.down);
final DiagonalDragBehavior diagonalDragBehavior;
@override
_VerticalOuterDimensionState createState() => _VerticalOuterDimensionState();
}
class _VerticalOuterDimensionState extends ScrollableState {
DiagonalDragBehavior get diagonalDragBehavior => (widget as _VerticalOuterDimension).diagonalDragBehavior;
@override
void setCanDrag(bool value) {
switch (diagonalDragBehavior) {
case DiagonalDragBehavior.none:
// If we aren't scrolling diagonally, the default drag gesture
// recognizer is used.
super.setCanDrag(value);
return;
case DiagonalDragBehavior.weightedEvent:
case DiagonalDragBehavior.weightedContinuous:
case DiagonalDragBehavior.free:
if (value) {
// If a type of diagonal scrolling is enabled, a panning gesture
// recognizer will be created for the _InnerDimension. So in this
// case, the _OuterDimension does not require a gesture recognizer.
_gestureRecognizers = const <Type, GestureRecognizerFactory>{};
// Cancel the active hold/drag (if any) because the gesture recognizers
// will soon be disposed by our RawGestureDetector, and we won't be
// receiving pointer up events to cancel the hold/drag.
_handleDragCancel();
_lastCanDrag = value;
_lastAxisDirection = widget.axis;
if (_gestureDetectorKey.currentState != null) {
_gestureDetectorKey.currentState!.replaceGestureRecognizers(_gestureRecognizers);
}
}
return;
}
}
@override
Widget _buildChrome(BuildContext context, Widget child) {
final ScrollableDetails details = ScrollableDetails(
direction: widget.axisDirection,
controller: _effectiveScrollController,
clipBehavior: widget.clipBehavior,
);
// Skip building a scrollbar here, the dual scrollbar is added in
// TwoDimensionalScrollableState.
return _configuration.buildOverscrollIndicator(context, child, details);
}
}
// Horizontal inner scrollable of 2D scrolling
class _HorizontalInnerDimension extends Scrollable {
const _HorizontalInnerDimension({
super.key,
required super.viewportBuilder,
required super.axisDirection,
super.controller,
super.physics,
super.clipBehavior,
super.incrementCalculator,
super.excludeFromSemantics,
super.dragStartBehavior,
super.restorationId,
this.diagonalDragBehavior = DiagonalDragBehavior.none,
}) : assert(axisDirection == AxisDirection.left || axisDirection == AxisDirection.right);
final DiagonalDragBehavior diagonalDragBehavior;
@override
_HorizontalInnerDimensionState createState() => _HorizontalInnerDimensionState();
}
class _HorizontalInnerDimensionState extends ScrollableState {
late ScrollableState verticalScrollable;
Axis? lockedAxis;
Offset? lastDragOffset;
DiagonalDragBehavior get diagonalDragBehavior => (widget as _HorizontalInnerDimension).diagonalDragBehavior;
@override
void didChangeDependencies() {
verticalScrollable = Scrollable.of(context);
assert(axisDirectionToAxis(verticalScrollable.axisDirection) == Axis.vertical);
super.didChangeDependencies();
}
void _evaluateLockedAxis(Offset offset) {
assert(lastDragOffset != null);
final Offset offsetDelta = lastDragOffset! - offset;
final double axisDifferential = offsetDelta.dx.abs() - offsetDelta.dy.abs();
if (axisDifferential.abs() >= kTouchSlop) {
// We have single axis winner.
lockedAxis = axisDifferential > 0.0 ? Axis.horizontal : Axis.vertical;
} else {
lockedAxis = null;
}
}
@override
void _handleDragDown(DragDownDetails details) {
switch (diagonalDragBehavior) {
case DiagonalDragBehavior.none:
break;
case DiagonalDragBehavior.weightedEvent:
case DiagonalDragBehavior.weightedContinuous:
case DiagonalDragBehavior.free:
// Initiate hold. If one or the other wins the gesture, cancel the
// opposite axis.
verticalScrollable._handleDragDown(details);
}
super._handleDragDown(details);
}
@override
void _handleDragStart(DragStartDetails details) {
lastDragOffset = details.globalPosition;
switch (diagonalDragBehavior) {
case DiagonalDragBehavior.none:
break;
case DiagonalDragBehavior.weightedEvent:
case DiagonalDragBehavior.weightedContinuous:
// See if one axis wins the drag.
_evaluateLockedAxis(details.globalPosition);
switch (lockedAxis) {
case null:
// Prepare to scroll diagonally
verticalScrollable._handleDragStart(details);
case Axis.horizontal:
// Prepare to scroll horizontally.
super._handleDragStart(details);
return;
case Axis.vertical:
// Prepare to scroll vertically.
verticalScrollable._handleDragStart(details);
return;
}
case DiagonalDragBehavior.free:
verticalScrollable._handleDragStart(details);
}
super._handleDragStart(details);
}
@override
void _handleDragUpdate(DragUpdateDetails details) {
final DragUpdateDetails verticalDragDetails = DragUpdateDetails(
sourceTimeStamp: details.sourceTimeStamp,
delta: Offset(0.0, details.delta.dy),
primaryDelta: details.delta.dy,
globalPosition: details.globalPosition,
localPosition: details.localPosition,
);
final DragUpdateDetails horizontalDragDetails = DragUpdateDetails(
sourceTimeStamp: details.sourceTimeStamp,
delta: Offset(details.delta.dx, 0.0),
primaryDelta: details.delta.dx,
globalPosition: details.globalPosition,
localPosition: details.localPosition,
);
switch (diagonalDragBehavior) {
case DiagonalDragBehavior.none:
// Default gesture handling from super class.
super._handleDragUpdate(horizontalDragDetails);
return;
case DiagonalDragBehavior.free:
// Scroll both axes
verticalScrollable._handleDragUpdate(verticalDragDetails);
super._handleDragUpdate(horizontalDragDetails);
return;
case DiagonalDragBehavior.weightedContinuous:
// Re-evaluate locked axis for every update.
_evaluateLockedAxis(details.globalPosition);
lastDragOffset = details.globalPosition;
case DiagonalDragBehavior.weightedEvent:
// Lock axis only once per gesture.
if (lockedAxis == null && lastDragOffset != null) {
// A winner has not been declared yet.
// See if one axis has won the drag.
_evaluateLockedAxis(details.globalPosition);
}
}
switch (lockedAxis) {
case null:
// Scroll diagonally
verticalScrollable._handleDragUpdate(verticalDragDetails);
super._handleDragUpdate(horizontalDragDetails);
case Axis.horizontal:
// Scroll horizontally
super._handleDragUpdate(horizontalDragDetails);
return;
case Axis.vertical:
// Scroll vertically
verticalScrollable._handleDragUpdate(verticalDragDetails);
return;
}
}
@override
void _handleDragEnd(DragEndDetails details) {
lastDragOffset = null;
lockedAxis = null;
final double dx = details.velocity.pixelsPerSecond.dx;
final double dy = details.velocity.pixelsPerSecond.dy;
final DragEndDetails verticalDragDetails = DragEndDetails(
velocity: Velocity(pixelsPerSecond: Offset(0.0, dy)),
primaryVelocity: details.velocity.pixelsPerSecond.dy,
);
final DragEndDetails horizontalDragDetails = DragEndDetails(
velocity: Velocity(pixelsPerSecond: Offset(dx, 0.0)),
primaryVelocity: details.velocity.pixelsPerSecond.dx,
);
switch (diagonalDragBehavior) {
case DiagonalDragBehavior.none:
break;
case DiagonalDragBehavior.weightedEvent:
case DiagonalDragBehavior.weightedContinuous:
case DiagonalDragBehavior.free:
verticalScrollable._handleDragEnd(verticalDragDetails);
}
super._handleDragEnd(horizontalDragDetails);
}
@override
void _handleDragCancel() {
lastDragOffset = null;
lockedAxis = null;
switch (diagonalDragBehavior) {
case DiagonalDragBehavior.none:
break;
case DiagonalDragBehavior.weightedEvent:
case DiagonalDragBehavior.weightedContinuous:
case DiagonalDragBehavior.free:
verticalScrollable._handleDragCancel();
}
super._handleDragCancel();
}
@override
void setCanDrag(bool value) {
switch (diagonalDragBehavior) {
case DiagonalDragBehavior.none:
// If we aren't scrolling diagonally, the default drag gesture recognizer
// is used.
super.setCanDrag(value);
return;
case DiagonalDragBehavior.weightedEvent:
case DiagonalDragBehavior.weightedContinuous:
case DiagonalDragBehavior.free:
if (value) {
// Replaces the typical vertical/horizontal drag gesture recognizers
// with a pan gesture recognizer to allow bidirectional scrolling.
// Based on the diagonalDragBehavior, valid horizontal deltas are
// applied to this scrollable, while vertical deltas are routed to
// the vertical scrollable.
_gestureRecognizers = <Type, GestureRecognizerFactory>{
PanGestureRecognizer: GestureRecognizerFactoryWithHandlers<PanGestureRecognizer>(
() => PanGestureRecognizer(supportedDevices: _configuration.dragDevices),
(PanGestureRecognizer instance) {
instance
..onDown = _handleDragDown
..onStart = _handleDragStart
..onUpdate = _handleDragUpdate
..onEnd = _handleDragEnd
..onCancel = _handleDragCancel
..minFlingDistance = _physics?.minFlingDistance
..minFlingVelocity = _physics?.minFlingVelocity
..maxFlingVelocity = _physics?.maxFlingVelocity
..velocityTrackerBuilder = _configuration.velocityTrackerBuilder(context)
..dragStartBehavior = widget.dragStartBehavior
..gestureSettings = _mediaQueryGestureSettings;
},
),
};
// Cancel the active hold/drag (if any) because the gesture recognizers
// will soon be disposed by our RawGestureDetector, and we won't be
// receiving pointer up events to cancel the hold/drag.
_handleDragCancel();
_lastCanDrag = value;
_lastAxisDirection = widget.axis;
if (_gestureDetectorKey.currentState != null) {
_gestureDetectorKey.currentState!.replaceGestureRecognizers(_gestureRecognizers);
}
}
return;
}
}
@override
Widget _buildChrome(BuildContext context, Widget child) {
final ScrollableDetails details = ScrollableDetails(
direction: widget.axisDirection,
controller: _effectiveScrollController,
clipBehavior: widget.clipBehavior,
);
// Skip building a scrollbar here, the dual scrollbar is added in
// TwoDimensionalScrollableState.
return _configuration.buildOverscrollIndicator(context, child, details);
}
}

View File

@@ -22,10 +22,8 @@ import 'scrollable.dart';
export 'package:flutter/physics.dart' show Tolerance;
/// Describes the aspects of a Scrollable widget to inform inherited widgets
/// like [ScrollBehavior] for decorating.
// TODO(Piinks): Fix doc with 2DScrollable change.
// or enumerate the properties of combined
// Scrollables, such as [TwoDimensionalScrollable].
/// like [ScrollBehavior] for decorating or enumerate the properties of combined
/// Scrollables, such as [TwoDimensionalScrollable].
///
/// Decorations like [GlowingOverscrollIndicator]s and [Scrollbar]s require
/// information about the Scrollable in order to be initialized.

View File

@@ -0,0 +1,206 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'focus_manager.dart';
import 'focus_scope.dart';
import 'framework.dart';
import 'notification_listener.dart';
import 'primary_scroll_controller.dart';
import 'scroll_controller.dart';
import 'scroll_delegate.dart';
import 'scroll_notification.dart';
import 'scroll_physics.dart';
import 'scroll_view.dart';
import 'scrollable.dart';
import 'scrollable_helpers.dart';
import 'two_dimensional_viewport.dart';
/// A widget that combines a [TwoDimensionalScrollable] and a
/// [TwoDimensionalViewport] to create an interactive scrolling pane of content
/// in both vertical and horizontal dimensions.
///
/// A two-way scrollable widget consist of three pieces:
///
/// 1. A [TwoDimensionalScrollable] widget, which listens for various user
/// gestures and implements the interaction design for scrolling.
/// 2. A [TwoDimensionalViewport] widget, which implements the visual design
/// for scrolling by displaying only a portion
/// of the widgets inside the scroll view.
/// 3. A [TwoDimensionalChildDelegate], which provides the children visible in
/// the scroll view.
///
/// [TwoDimensionalScrollView] helps orchestrate these pieces by creating the
/// [TwoDimensionalScrollable] and deferring to its subclass to implement
/// [buildViewport], which builds a subclass of [TwoDimensionalViewport]. The
/// [TwoDimensionalChildDelegate] is provided by the [delegate] parameter.
///
/// A [TwoDimensionalScrollView] has two different [ScrollPosition]s, one for
/// each [Axis]. This means that there are also two unique [ScrollController]s
/// for these positions. To provide a ScrollController to access the
/// ScrollPosition, use the [ScrollableDetails.controller] property of the
/// associated axis that is provided to this scroll view.
abstract class TwoDimensionalScrollView extends StatelessWidget {
/// Creates a widget that scrolls in both dimensions.
///
/// The [primary] argument is associated with the [mainAxis]. The main axis
/// [ScrollableDetails.controller] must be null if [primary] is configured for
/// that axis. If [primary] is true, the nearest [PrimaryScrollController]
/// surrounding the widget is attached to the scroll position of that axis.
const TwoDimensionalScrollView({
super.key,
this.primary,
this.mainAxis = Axis.vertical,
this.verticalDetails = const ScrollableDetails.vertical(),
this.horizontalDetails = const ScrollableDetails.horizontal(),
required this.delegate,
this.cacheExtent,
this.diagonalDragBehavior = DiagonalDragBehavior.none,
this.dragStartBehavior = DragStartBehavior.start,
this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
this.clipBehavior = Clip.hardEdge,
});
/// A delegate that provides the children for the [TwoDimensionalScrollView].
final TwoDimensionalChildDelegate delegate;
/// {@macro flutter.rendering.RenderViewportBase.cacheExtent}
final double? cacheExtent;
/// Whether scrolling gestures should lock to one axes, allow free movement
/// in both axes, or be evaluated on a weighted scale.
///
/// Defaults to [DiagonalDragBehavior.none], locking axes to receive input one
/// at a time.
final DiagonalDragBehavior diagonalDragBehavior;
/// {@macro flutter.widgets.scroll_view.primary}
final bool? primary;
/// The main axis of the two.
///
/// Used to determine how to apply [primary] when true.
///
/// This value should also be provided to the subclass of
/// [TwoDimensionalViewport], where it is used to determine paint order of
/// children.
final Axis mainAxis;
/// The configuration of the vertical Scrollable.
///
/// These [ScrollableDetails] can be used to set the [AxisDirection],
/// [ScrollController], [ScrollPhysics] and more for the vertical axis.
final ScrollableDetails verticalDetails;
/// The configuration of the horizontal Scrollable.
///
/// These [ScrollableDetails] can be used to set the [AxisDirection],
/// [ScrollController], [ScrollPhysics] and more for the horizontal axis.
final ScrollableDetails horizontalDetails;
/// {@macro flutter.widgets.scrollable.dragStartBehavior}
final DragStartBehavior dragStartBehavior;
/// {@macro flutter.widgets.scroll_view.keyboardDismissBehavior}
final ScrollViewKeyboardDismissBehavior keyboardDismissBehavior;
/// {@macro flutter.material.Material.clipBehavior}
///
/// Defaults to [Clip.hardEdge].
final Clip clipBehavior;
/// Build the two dimensional viewport.
///
/// Subclasses may override this method to change how the viewport is built,
/// likely a subclass of [TwoDimensionalViewport].
///
/// The `verticalOffset` and `horizontalOffset` arguments are the values
/// obtained from [TwoDimensionalScrollable.viewportBuilder].
Widget buildViewport(
BuildContext context,
ViewportOffset verticalOffset,
ViewportOffset horizontalOffset,
);
@override
Widget build(BuildContext context) {
assert(
axisDirectionToAxis(verticalDetails.direction) == Axis.vertical,
'TwoDimensionalScrollView.verticalDetails are not Axis.vertical.'
);
assert(
axisDirectionToAxis(horizontalDetails.direction) == Axis.horizontal,
'TwoDimensionalScrollView.horizontalDetails are not Axis.horizontal.'
);
ScrollableDetails mainAxisDetails = switch (mainAxis) {
Axis.vertical => verticalDetails,
Axis.horizontal => horizontalDetails,
};
final bool effectivePrimary = primary
?? mainAxisDetails.controller == null && PrimaryScrollController.shouldInherit(
context,
mainAxis,
);
if (effectivePrimary) {
// Using PrimaryScrollController for mainAxis.
assert(
mainAxisDetails.controller == null,
'TwoDimensionalScrollView.primary was explicitly set to true, but a '
'ScrollController was provided in the ScrollableDetails of the '
'TwoDimensionalScrollView.mainAxis.'
);
mainAxisDetails = mainAxisDetails.copyWith(
controller: PrimaryScrollController.of(context),
);
}
final TwoDimensionalScrollable scrollable = TwoDimensionalScrollable(
horizontalDetails : switch (mainAxis) {
Axis.horizontal => mainAxisDetails,
Axis.vertical => horizontalDetails,
},
verticalDetails: switch (mainAxis) {
Axis.vertical => mainAxisDetails,
Axis.horizontal => verticalDetails,
},
diagonalDragBehavior: diagonalDragBehavior,
viewportBuilder: buildViewport,
dragStartBehavior: dragStartBehavior,
);
final Widget scrollableResult = effectivePrimary
// Further descendant ScrollViews will not inherit the same PrimaryScrollController
? PrimaryScrollController.none(child: scrollable)
: scrollable;
if (keyboardDismissBehavior == ScrollViewKeyboardDismissBehavior.onDrag) {
return NotificationListener<ScrollUpdateNotification>(
child: scrollableResult,
onNotification: (ScrollUpdateNotification notification) {
final FocusScopeNode focusScope = FocusScope.of(context);
if (notification.dragDetails != null && focusScope.hasFocus) {
focusScope.unfocus();
}
return false;
},
);
}
return scrollableResult;
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(EnumProperty<Axis>('mainAxis', mainAxis));
properties.add(EnumProperty<DiagonalDragBehavior>('diagonalDragBehavior', diagonalDragBehavior));
properties.add(FlagProperty('primary', value: primary, ifTrue: 'using primary controller', showName: true));
properties.add(DiagnosticsProperty<ScrollableDetails>('verticalDetails', verticalDetails, showName: false));
properties.add(DiagnosticsProperty<ScrollableDetails>('horizontalDetails', horizontalDetails, showName: false));
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -13,7 +13,8 @@ export 'package:flutter/rendering.dart' show
AxisDirection,
GrowthDirection;
/// A widget that is bigger on the inside.
/// A widget through which a portion of larger content can be viewed, typically
/// in combination with a [Scrollable].
///
/// [Viewport] is the visual workhorse of the scrolling machinery. It displays a
/// subset of its children according to its own dimensions and the given

View File

@@ -149,6 +149,8 @@ export 'src/widgets/ticker_provider.dart';
export 'src/widgets/title.dart';
export 'src/widgets/transitions.dart';
export 'src/widgets/tween_animation_builder.dart';
export 'src/widgets/two_dimensional_scroll_view.dart';
export 'src/widgets/two_dimensional_viewport.dart';
export 'src/widgets/undo_history.dart';
export 'src/widgets/unique_widget.dart';
export 'src/widgets/value_listenable_builder.dart';

View File

@@ -0,0 +1,327 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// 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';
import 'package:flutter/material.dart';
import 'package:flutter/src/gestures/monodrag.dart';
import 'package:flutter_test/flutter_test.dart';
import 'two_dimensional_utils.dart';
Widget? _testChildBuilder(BuildContext context, ChildVicinity vicinity) {
return SizedBox(
height: 200,
width: 200,
child: Center(child: Text('C${vicinity.xIndex}:R${vicinity.yIndex}')),
);
}
void main() {
group('TwoDimensionalScrollView',() {
testWidgets('asserts the axis directions do not conflict with one another', (WidgetTester tester) async {
final List<Object> exceptions = <Object>[];
final FlutterExceptionHandler? oldHandler = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails details) {
exceptions.add(details.exception);
};
// Horizontal wrong
await tester.pumpWidget(MaterialApp(
home: SimpleBuilderTableView(
delegate: TwoDimensionalChildBuilderDelegate(builder: (_, __) => null),
horizontalDetails: const ScrollableDetails.vertical(),
// Horizontal has default const ScrollableDetails.horizontal()
),
));
// Vertical wrong
await tester.pumpWidget(MaterialApp(
home: SimpleBuilderTableView(
delegate: TwoDimensionalChildBuilderDelegate(builder: (_, __) => null),
verticalDetails: const ScrollableDetails.horizontal(),
// Horizontal has default const ScrollableDetails.horizontal()
),
));
// Both wrong
await tester.pumpWidget(MaterialApp(
home: SimpleBuilderTableView(
delegate: TwoDimensionalChildBuilderDelegate(builder: (_, __) => null),
verticalDetails: const ScrollableDetails.horizontal(),
horizontalDetails: const ScrollableDetails.vertical(),
),
));
FlutterError.onError = oldHandler;
expect(exceptions.length, 3);
for (final Object exception in exceptions) {
expect(exception, isAssertionError);
expect((exception as AssertionError).message, contains('are not Axis'));
}
}, variant: TargetPlatformVariant.all());
testWidgets('ScrollableDetails.controller can set initial scroll positions, modify within bounds', (WidgetTester tester) async {
final ScrollController verticalController = ScrollController(initialScrollOffset: 100);
final ScrollController horizontalController = ScrollController(initialScrollOffset: 50);
await tester.pumpWidget(MaterialApp(
home: SimpleBuilderTableView(
verticalDetails: ScrollableDetails.vertical(controller: verticalController),
horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController),
delegate: TwoDimensionalChildBuilderDelegate(
builder: _testChildBuilder,
maxXIndex: 99,
maxYIndex: 99,
),
),
));
await tester.pumpAndSettle();
expect(verticalController.position.pixels, 100);
expect(verticalController.position.maxScrollExtent, 19400);
expect(horizontalController.position.pixels, 50);
expect(horizontalController.position.maxScrollExtent, 19200);
verticalController.jumpTo(verticalController.position.maxScrollExtent);
horizontalController.jumpTo(horizontalController.position.maxScrollExtent);
await tester.pump();
expect(verticalController.position.pixels, 19400);
expect(horizontalController.position.pixels, 19200);
// Out of bounds
verticalController.jumpTo(verticalController.position.maxScrollExtent + 100);
horizontalController.jumpTo(horizontalController.position.maxScrollExtent + 100);
// Account for varying scroll physics for different platforms (overscroll)
await tester.pumpAndSettle();
expect(verticalController.position.pixels, 19400);
expect(horizontalController.position.pixels, 19200);
}, variant: TargetPlatformVariant.all());
testWidgets('Properly assigns the PrimaryScrollController to the main axis on the correct platform', (WidgetTester tester) async {
late ScrollController controller;
Widget buildForPrimaryScrollController({
bool? explicitPrimary,
Axis mainAxis = Axis.vertical,
bool addControllerConflict = false,
}) {
return MaterialApp(
home: PrimaryScrollController(
controller: controller,
child: SimpleBuilderTableView(
mainAxis: mainAxis,
primary: explicitPrimary,
verticalDetails: ScrollableDetails.vertical(
controller: addControllerConflict && mainAxis == Axis.vertical
? ScrollController()
: null
),
horizontalDetails: ScrollableDetails.horizontal(
controller: addControllerConflict && mainAxis == Axis.horizontal
? ScrollController()
: null
),
delegate: TwoDimensionalChildBuilderDelegate(
builder: _testChildBuilder,
maxXIndex: 99,
maxYIndex: 99,
),
),
),
);
}
// Horizontal default - horizontal never automatically adopts PSC
controller = ScrollController();
await tester.pumpWidget(buildForPrimaryScrollController(
mainAxis: Axis.horizontal,
));
await tester.pumpAndSettle();
switch (defaultTargetPlatform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
expect(controller.hasClients, isFalse);
}
// Horizontal explicitly true
controller = ScrollController();
await tester.pumpWidget(buildForPrimaryScrollController(
mainAxis: Axis.horizontal,
explicitPrimary: true,
));
await tester.pumpAndSettle();
switch (defaultTargetPlatform) {
// Primary explicitly true is always adopted.
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
expect(controller.hasClients, isTrue);
expect(controller.position.axis, Axis.horizontal);
}
// Horizontal explicitly false
controller = ScrollController();
await tester.pumpWidget(buildForPrimaryScrollController(
mainAxis: Axis.horizontal,
explicitPrimary: false,
));
await tester.pumpAndSettle();
switch (defaultTargetPlatform) {
// Primary explicitly false is never adopted.
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
expect(controller.hasClients, isFalse);
}
// Vertical default
controller = ScrollController();
await tester.pumpWidget(buildForPrimaryScrollController());
await tester.pumpAndSettle();
switch (defaultTargetPlatform) {
// Mobile platforms inherit the PSC without explicitly setting
// primary
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
expect(controller.hasClients, isTrue);
expect(controller.position.axis, Axis.vertical);
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
expect(controller.hasClients, isFalse);
}
// Vertical explicitly true
controller = ScrollController();
await tester.pumpWidget(buildForPrimaryScrollController(
explicitPrimary: true,
));
await tester.pumpAndSettle();
switch (defaultTargetPlatform) {
// Primary explicitly true is always adopted.
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
expect(controller.hasClients, isTrue);
expect(controller.position.axis, Axis.vertical);
}
// Vertical explicitly false
controller = ScrollController();
await tester.pumpWidget(buildForPrimaryScrollController(
explicitPrimary: false,
));
await tester.pumpAndSettle();
switch (defaultTargetPlatform) {
// Primary explicitly false is never adopted.
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
expect(controller.hasClients, isFalse);
}
// Assertions
final List<Object> exceptions = <Object>[];
final FlutterExceptionHandler? oldHandler = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails details) {
exceptions.add(details.exception);
};
// Vertical asserts ScrollableDetails.controller has not been provided if
// primary is explicitly set
controller = ScrollController();
await tester.pumpWidget(buildForPrimaryScrollController(
explicitPrimary: true,
addControllerConflict: true,
));
expect(exceptions.length, 1);
expect(exceptions[0], isAssertionError);
expect(
(exceptions[0] as AssertionError).message,
contains('TwoDimensionalScrollView.primary was explicitly set to true'),
);
exceptions.clear();
// Horizontal asserts ScrollableDetails.controller has not been provided
// if primary is explicitly set true
controller = ScrollController();
await tester.pumpWidget(buildForPrimaryScrollController(
mainAxis: Axis.horizontal,
explicitPrimary: true,
addControllerConflict: true,
));
expect(exceptions.length, 1);
expect(exceptions[0], isAssertionError);
expect(
(exceptions[0] as AssertionError).message,
contains('TwoDimensionalScrollView.primary was explicitly set to true'),
);
FlutterError.onError = oldHandler;
}, variant: TargetPlatformVariant.all());
testWidgets('TwoDimensionalScrollable receives the correct details from TwoDimensionalScrollView', (WidgetTester tester) async {
late BuildContext capturedContext;
// Default
await tester.pumpWidget(MaterialApp(
home: SimpleBuilderTableView(
delegate: TwoDimensionalChildBuilderDelegate(
builder: (BuildContext context, ChildVicinity vicinity) {
capturedContext = context;
return Text(vicinity.toString());
},
),
),
));
await tester.pumpAndSettle();
TwoDimensionalScrollableState scrollable = TwoDimensionalScrollable.of(
capturedContext,
);
expect(scrollable.widget.verticalDetails.direction, AxisDirection.down);
expect(scrollable.widget.horizontalDetails.direction, AxisDirection.right);
expect(scrollable.widget.diagonalDragBehavior, DiagonalDragBehavior.none);
expect(scrollable.widget.dragStartBehavior, DragStartBehavior.start);
// Customized
await tester.pumpWidget(MaterialApp(
home: SimpleBuilderTableView(
verticalDetails: const ScrollableDetails.vertical(reverse: true),
horizontalDetails: const ScrollableDetails.horizontal(reverse: true),
diagonalDragBehavior: DiagonalDragBehavior.weightedContinuous,
dragStartBehavior: DragStartBehavior.down,
delegate: TwoDimensionalChildBuilderDelegate(
builder: _testChildBuilder,
),
),
));
await tester.pumpAndSettle();
scrollable = TwoDimensionalScrollable.of(capturedContext);
expect(scrollable.widget.verticalDetails.direction, AxisDirection.up);
expect(scrollable.widget.horizontalDetails.direction, AxisDirection.left);
expect(scrollable.widget.diagonalDragBehavior, DiagonalDragBehavior.weightedContinuous);
expect(scrollable.widget.dragStartBehavior, DragStartBehavior.down);
}, variant: TargetPlatformVariant.all());
});
}

View File

@@ -0,0 +1,424 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:math' as math;
import 'package:flutter/foundation.dart' show clampDouble;
import 'package:flutter/gestures.dart' show DragStartBehavior;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart' show ViewportOffset;
// BUILDER DELEGATE ---
final TwoDimensionalChildBuilderDelegate builderDelegate = TwoDimensionalChildBuilderDelegate(
maxXIndex: 5,
maxYIndex: 5,
builder: (BuildContext context, ChildVicinity vicinity) {
return Container(
color: vicinity.xIndex.isEven && vicinity.yIndex.isEven
? Colors.amber[100]
: (vicinity.xIndex.isOdd && vicinity.yIndex.isOdd
? Colors.blueAccent[100]
: null),
height: 200,
width: 200,
child: Center(child: Text('R${vicinity.xIndex}:C${vicinity.yIndex}')),
);
}
);
// Creates a simple 2D table of 200x200 squares with a builder delegate.
Widget simpleBuilderTest({
Axis mainAxis = Axis.vertical,
bool? primary,
ScrollableDetails? verticalDetails,
ScrollableDetails? horizontalDetails,
TwoDimensionalChildBuilderDelegate? delegate,
double? cacheExtent,
DiagonalDragBehavior? diagonalDrag,
Clip? clipBehavior,
String? restorationID,
bool useCacheExtent = false,
bool applyDimensions = true,
bool forgetToLayoutChild = false,
bool setLayoutOffset = true,
}) {
return MaterialApp(
restorationScopeId: restorationID,
home: Scaffold(
body: SimpleBuilderTableView(
mainAxis: mainAxis,
verticalDetails: verticalDetails ?? const ScrollableDetails.vertical(),
horizontalDetails: horizontalDetails ?? const ScrollableDetails.horizontal(),
cacheExtent: cacheExtent,
useCacheExtent: useCacheExtent,
diagonalDragBehavior: diagonalDrag ?? DiagonalDragBehavior.none,
clipBehavior: clipBehavior ?? Clip.hardEdge,
delegate: delegate ?? builderDelegate,
applyDimensions: applyDimensions,
forgetToLayoutChild: forgetToLayoutChild,
setLayoutOffset: setLayoutOffset,
),
),
);
}
class SimpleBuilderTableView extends TwoDimensionalScrollView {
const SimpleBuilderTableView({
super.key,
super.primary,
super.mainAxis = Axis.vertical,
super.verticalDetails = const ScrollableDetails.vertical(),
super.horizontalDetails = const ScrollableDetails.horizontal(),
required TwoDimensionalChildBuilderDelegate delegate,
super.cacheExtent,
super.diagonalDragBehavior = DiagonalDragBehavior.none,
super.dragStartBehavior = DragStartBehavior.start,
super.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
super.clipBehavior = Clip.hardEdge,
this.useCacheExtent = false,
this.applyDimensions = true,
this.forgetToLayoutChild = false,
this.setLayoutOffset = true,
}) : super(delegate: delegate);
// Piped through for testing in RenderTwoDimensionalViewport
final bool useCacheExtent;
final bool applyDimensions;
final bool forgetToLayoutChild;
final bool setLayoutOffset;
@override
Widget buildViewport(BuildContext context, ViewportOffset verticalOffset, ViewportOffset horizontalOffset) {
return SimpleBuilderTableViewport(
horizontalOffset: horizontalOffset,
horizontalAxisDirection: horizontalDetails.direction,
verticalOffset: verticalOffset,
verticalAxisDirection: verticalDetails.direction,
mainAxis: mainAxis,
delegate: delegate as TwoDimensionalChildBuilderDelegate,
cacheExtent: cacheExtent,
clipBehavior: clipBehavior,
useCacheExtent: useCacheExtent,
applyDimensions: applyDimensions,
forgetToLayoutChild: forgetToLayoutChild,
setLayoutOffset: setLayoutOffset,
);
}
}
class SimpleBuilderTableViewport extends TwoDimensionalViewport {
const SimpleBuilderTableViewport({
super.key,
required super.verticalOffset,
required super.verticalAxisDirection,
required super.horizontalOffset,
required super.horizontalAxisDirection,
required TwoDimensionalChildBuilderDelegate delegate,
required super.mainAxis,
super.cacheExtent,
super.clipBehavior = Clip.hardEdge,
this.useCacheExtent = false,
this.applyDimensions = true,
this.forgetToLayoutChild = false,
this.setLayoutOffset = true,
}) : super(delegate: delegate);
// Piped through for testing in RenderTwoDimensionalViewport
final bool useCacheExtent;
final bool applyDimensions;
final bool forgetToLayoutChild;
final bool setLayoutOffset;
@override
RenderTwoDimensionalViewport createRenderObject(BuildContext context) {
return RenderSimpleBuilderTableViewport(
horizontalOffset: horizontalOffset,
horizontalAxisDirection: horizontalAxisDirection,
verticalOffset: verticalOffset,
verticalAxisDirection: verticalAxisDirection,
mainAxis: mainAxis,
delegate: delegate as TwoDimensionalChildBuilderDelegate,
childManager: context as TwoDimensionalChildManager,
cacheExtent: cacheExtent,
clipBehavior: clipBehavior,
useCacheExtent: useCacheExtent,
applyDimensions: applyDimensions,
forgetToLayoutChild: forgetToLayoutChild,
setLayoutOffset: setLayoutOffset,
);
}
@override
void updateRenderObject(BuildContext context, RenderSimpleBuilderTableViewport renderObject) {
renderObject
..horizontalOffset = horizontalOffset
..horizontalAxisDirection = horizontalAxisDirection
..verticalOffset = verticalOffset
..verticalAxisDirection = verticalAxisDirection
..mainAxis = mainAxis
..delegate = delegate
..cacheExtent = cacheExtent
..clipBehavior = clipBehavior;
}
}
class RenderSimpleBuilderTableViewport extends RenderTwoDimensionalViewport {
RenderSimpleBuilderTableViewport({
required super.horizontalOffset,
required super.horizontalAxisDirection,
required super.verticalOffset,
required super.verticalAxisDirection,
required TwoDimensionalChildBuilderDelegate delegate,
required super.mainAxis,
required super.childManager,
super.cacheExtent,
super.clipBehavior = Clip.hardEdge,
this.applyDimensions = true,
this.setLayoutOffset = true,
this.useCacheExtent = false,
this.forgetToLayoutChild = false,
}) : super(delegate: delegate);
// These are to test conditions to validate subclass implementations after
// layoutChildSequence
final bool applyDimensions;
final bool setLayoutOffset;
final bool useCacheExtent;
final bool forgetToLayoutChild;
RenderBox? testGetChildFor(ChildVicinity vicinity) => getChildFor(vicinity);
@override
void layoutChildSequence() {
// Really simple table implementation for testing.
// Every child is 200x200 square
final double horizontalPixels = horizontalOffset.pixels;
final double verticalPixels = verticalOffset.pixels;
final double viewportWidth = viewportDimension.width + (useCacheExtent ? cacheExtent : 0.0);
final double viewportHeight = viewportDimension.height + (useCacheExtent ? cacheExtent : 0.0);
final TwoDimensionalChildBuilderDelegate builderDelegate = delegate as TwoDimensionalChildBuilderDelegate;
final int maxRowIndex;
final int maxColumnIndex;
maxRowIndex = builderDelegate.maxYIndex ?? 5;
maxColumnIndex = builderDelegate.maxXIndex ?? 5;
final int leadingColumn = math.max((horizontalPixels / 200).floor(), 0);
final int leadingRow = math.max((verticalPixels / 200).floor(), 0);
final int trailingColumn = math.min(
((horizontalPixels + viewportWidth) / 200).ceil(),
maxColumnIndex,
);
final int trailingRow = math.min(
((verticalPixels + viewportHeight) / 200).ceil(),
maxRowIndex,
);
double xLayoutOffset = (leadingColumn * 200) - horizontalOffset.pixels;
for (int column = leadingColumn; column <= trailingColumn; column++) {
double yLayoutOffset = (leadingRow * 200) - verticalOffset.pixels;
for (int row = leadingRow; row <= trailingRow; row++) {
final ChildVicinity vicinity = ChildVicinity(xIndex: column, yIndex: row);
final RenderBox child = buildOrObtainChildFor(vicinity)!;
if (!forgetToLayoutChild) {
child.layout(constraints.tighten(width: 200.0, height: 200.0));
}
if (setLayoutOffset) {
parentDataOf(child).layoutOffset = Offset(xLayoutOffset, yLayoutOffset);
}
yLayoutOffset += 200;
}
xLayoutOffset += 200;
}
if (applyDimensions) {
final double verticalExtent = 200 * (maxRowIndex + 1);
verticalOffset.applyContentDimensions(
0.0,
clampDouble(verticalExtent - viewportDimension.height, 0.0, double.infinity),
);
final double horizontalExtent = 200 * (maxColumnIndex + 1);
horizontalOffset.applyContentDimensions(
0.0,
clampDouble(horizontalExtent - viewportDimension.width, 0.0, double.infinity),
);
}
}
}
// LIST DELEGATE ---
final List<List<Widget>> children = List<List<Widget>>.generate(
100,
(int xIndex) {
return List<Widget>.generate(
100,
(int yIndex) {
return Container(
color: xIndex.isEven && yIndex.isEven
? Colors.amber[100]
: (xIndex.isOdd && yIndex.isOdd
? Colors.blueAccent[100]
: null),
height: 200,
width: 200,
child: Center(child: Text('R$xIndex:C$yIndex')),
);
},
);
},
);
// Builds a simple 2D table of 200x200 squares with a list delegate.
Widget simpleListTest({
Axis mainAxis = Axis.vertical,
bool? primary,
ScrollableDetails? verticalDetails,
ScrollableDetails? horizontalDetails,
TwoDimensionalChildListDelegate? delegate,
double? cacheExtent,
DiagonalDragBehavior? diagonalDrag,
Clip? clipBehavior,
}) {
return MaterialApp(
home: Scaffold(
body: SimpleListTableView(
mainAxis: mainAxis,
verticalDetails: verticalDetails ?? const ScrollableDetails.vertical(),
horizontalDetails: horizontalDetails ?? const ScrollableDetails.horizontal(),
cacheExtent: cacheExtent,
diagonalDragBehavior: diagonalDrag ?? DiagonalDragBehavior.none,
clipBehavior: clipBehavior ?? Clip.hardEdge,
delegate: delegate ?? TwoDimensionalChildListDelegate(children: children),
),
),
);
}
class SimpleListTableView extends TwoDimensionalScrollView {
const SimpleListTableView({
super.key,
super.primary,
super.mainAxis = Axis.vertical,
super.verticalDetails = const ScrollableDetails.vertical(),
super.horizontalDetails = const ScrollableDetails.horizontal(),
required TwoDimensionalChildListDelegate delegate,
super.cacheExtent,
super.diagonalDragBehavior = DiagonalDragBehavior.none,
super.dragStartBehavior = DragStartBehavior.start,
super.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
super.clipBehavior = Clip.hardEdge,
}) : super(delegate: delegate);
@override
Widget buildViewport(BuildContext context, ViewportOffset verticalOffset, ViewportOffset horizontalOffset) {
return SimpleListTableViewport(
horizontalOffset: horizontalOffset,
horizontalAxisDirection: horizontalDetails.direction,
verticalOffset: verticalOffset,
verticalAxisDirection: verticalDetails.direction,
mainAxis: mainAxis,
delegate: delegate as TwoDimensionalChildListDelegate,
cacheExtent: cacheExtent,
clipBehavior: clipBehavior,
);
}
}
class SimpleListTableViewport extends TwoDimensionalViewport {
const SimpleListTableViewport({
super.key,
required super.verticalOffset,
required super.verticalAxisDirection,
required super.horizontalOffset,
required super.horizontalAxisDirection,
required TwoDimensionalChildListDelegate delegate,
required super.mainAxis,
super.cacheExtent,
super.clipBehavior = Clip.hardEdge,
}) : super(delegate: delegate);
@override
RenderTwoDimensionalViewport createRenderObject(BuildContext context) {
return RenderSimpleListTableViewport(
horizontalOffset: horizontalOffset,
horizontalAxisDirection: horizontalAxisDirection,
verticalOffset: verticalOffset,
verticalAxisDirection: verticalAxisDirection,
mainAxis: mainAxis,
delegate: delegate as TwoDimensionalChildListDelegate,
childManager: context as TwoDimensionalChildManager,
cacheExtent: cacheExtent,
clipBehavior: clipBehavior,
);
}
@override
void updateRenderObject(BuildContext context, RenderSimpleListTableViewport renderObject) {
renderObject
..horizontalOffset = horizontalOffset
..horizontalAxisDirection = horizontalAxisDirection
..verticalOffset = verticalOffset
..verticalAxisDirection = verticalAxisDirection
..mainAxis = mainAxis
..delegate = delegate
..cacheExtent = cacheExtent
..clipBehavior = clipBehavior;
}
}
class RenderSimpleListTableViewport extends RenderTwoDimensionalViewport {
RenderSimpleListTableViewport({
required super.horizontalOffset,
required super.horizontalAxisDirection,
required super.verticalOffset,
required super.verticalAxisDirection,
required TwoDimensionalChildListDelegate delegate,
required super.mainAxis,
required super.childManager,
super.cacheExtent,
super.clipBehavior = Clip.hardEdge,
}) : super(delegate: delegate);
@override
void layoutChildSequence() {
// Really simple table implementation for testing.
// Every child is 200x200 square
final double horizontalPixels = horizontalOffset.pixels;
final double verticalPixels = verticalOffset.pixels;
final TwoDimensionalChildListDelegate listDelegate = delegate as TwoDimensionalChildListDelegate;
final int rowCount;
final int columnCount;
rowCount = listDelegate.children.length - 1;
columnCount = listDelegate.children[0].length - 1;
final int leadingColumn = math.max((horizontalPixels / 200).floor(), 0);
final int leadingRow = math.max((verticalPixels / 200).floor(), 0);
final int trailingColumn = math.min(
((horizontalPixels + viewportDimension.width) / 200).ceil(),
columnCount,
);
final int trailingRow = math.min(
((verticalPixels + viewportDimension.height) / 200).ceil(),
rowCount,
);
double xLayoutOffset = (leadingColumn * 200) - horizontalOffset.pixels;
for (int column = leadingColumn; column <= trailingColumn; column++) {
double yLayoutOffset = (leadingRow * 200) - verticalOffset.pixels;
for (int row = leadingRow; row <= trailingRow; row++) {
final ChildVicinity vicinity = ChildVicinity(xIndex: column, yIndex: row);
final RenderBox child = buildOrObtainChildFor(vicinity)!;
child.layout(constraints.tighten(width: 200.0, height: 200.0));
parentDataOf(child).layoutOffset = Offset(xLayoutOffset, yLayoutOffset);
yLayoutOffset += 200;
}
xLayoutOffset += 200;
}
verticalOffset.applyContentDimensions(0, 200 * 100 - viewportDimension.height);
horizontalOffset.applyContentDimensions(0, 200 * 100 - viewportDimension.width);
}
}

File diff suppressed because it is too large Load Diff