scroll_context.dart 2.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2015 The Chromium 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/scheduler.dart';
import 'package:flutter/rendering.dart';

import 'framework.dart';
import 'ticker_provider.dart';

11 12 13 14 15 16 17 18 19
/// An interface that [Scrollable] widgets implement in order to use
/// [ScrollPosition].
///
/// See also:
///
///  * [ScrollableState], which is the most common implementation of this
///    interface.
///  * [ScrollPosition], which uses this interface to communicate with the
///    scrollable widget.
20
abstract class ScrollContext {
21 22 23 24 25 26 27
  /// The [BuildContext] that should be used when dispatching
  /// [ScrollNotification]s.
  ///
  /// This context is typically different that the context of the scrollable
  /// widget itself. For example, [Scrollable] uses a context outside the
  /// [Viewport] but inside the widgets created by
  /// [ScrollBehavior.buildViewportChrome].
28
  BuildContext get notificationContext;
29

30 31 32 33 34 35 36 37
  /// The [BuildContext] that should be used when searching for a [PageStorage].
  ///
  /// This context is typically the context of the scrollable widget itself. In
  /// particular, it should involve any [GlobalKey]s that are dynamically
  /// created as part of creating the scrolling widget, since those would be
  /// different each time the widget is created.
  BuildContext get storageContext;

38
  /// A [TickerProvider] to use when animating the scroll position.
39
  TickerProvider get vsync;
40 41

  /// The direction in which the widget scrolls.
42 43
  AxisDirection get axisDirection;

44 45 46 47 48 49 50 51
  /// Whether the contents of the widget should ignore [PointerEvent] inputs.
  ///
  /// Setting this value to true prevents the use from interacting with the
  /// contents of the widget with pointer events. The widget itself is still
  /// interactive.
  ///
  /// For example, if the scroll position is being driven by an animation, it
  /// might be appropriate to set this value to ignore pointer events to
52
  /// prevent the user from accidentally interacting with the contents of the
53 54
  /// widget as it animates. The user will still be able to touch the widget,
  /// potentially stopping the animation.
55
  void setIgnorePointer(bool value);
56 57

  /// Whether the user can drag the widget, for example to initiate a scroll.
58
  void setCanDrag(bool value);
59 60 61

  /// Set the [SemanticsAction]s that should be expose to the semantics tree.
  void setSemanticsActions(Set<SemanticsAction> actions);
62
}