mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This patch makes a number of changes to how you can configure a
Scrollable2:
- The ScrollPhysics is now responsible for creating the ScrollPosition.
You can override the ScrollPhysics by supplying a `physics` argument
to `Scrollable`, and the new physics you supply will be applied to
the default physics inherited from the ScrollBehavior.
- This patch removes the ScrollPosition/AbsoluteScrollPosition split as
all clients were operating in pixels anyway and the split made the
code very difficult to follow.
- ScrollPosition no longer depends directly on Scrollable2State.
Instead, it depends on an abstract interface that Scrollable2State
implements. This change has two benefits:
a) It removes the circular dependency between ScrollPosition and
Scrollable2State, which lets us split the code for these classes
(and several other classes that got wrapped up in that cycle) into
separate libraries for easier maintenance.
b) ScrollPosition is no longer bound to Scrollable2, which means you
could use the behavior machinery to drive other sorts of widgets.
For example, we could use it to drive Scrollabe1 if we wanted.
56 lines
2.2 KiB
Dart
56 lines
2.2 KiB
Dart
// Copyright 2016 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 'tolerance.dart';
|
|
|
|
/// The base class for all simulations.
|
|
///
|
|
/// A simulation models an object, in a one-dimensional space, on which particular
|
|
/// forces are being applied, and exposes:
|
|
///
|
|
/// * The object's position, [x]
|
|
/// * The object's velocity, [dx]
|
|
/// * Whether the simulation is "done", [isDone]
|
|
///
|
|
/// A simulation is generally "done" if the object has, to a given [tolerance],
|
|
/// come to a complete rest.
|
|
///
|
|
/// The [x], [dx], and [isDone] functions take a time argument which specifies
|
|
/// the time for which they are to be evaluated. In principle, simulations can
|
|
/// be stateless, and thus can be queried with arbitrary times. In practice,
|
|
/// however, some simulations are not, and calling any of these functions will
|
|
/// advance the simulation to the given time.
|
|
///
|
|
/// As a general rule, therefore, a simulation should only be queried using
|
|
/// times that are equal to or greater than all times previously used for that
|
|
/// simulation.
|
|
///
|
|
/// Simulations do not specify units for distance, velocity, and time. Client
|
|
/// should establish a convention and use that convention consistently with all
|
|
/// related objects.
|
|
abstract class Simulation {
|
|
Simulation({ this.tolerance: Tolerance.defaultTolerance });
|
|
|
|
/// The position of the object in the simulation at the given time.
|
|
double x(double time);
|
|
|
|
/// The velocity of the object in the simulation at the given time.
|
|
double dx(double time);
|
|
|
|
/// Whether the simulation is "done" at the given time.
|
|
bool isDone(double time);
|
|
|
|
/// How close to the actual end of the simulation a value at a particular time
|
|
/// must be before [isDone] considers the simulation to be "done".
|
|
///
|
|
/// A simulation with an asymptotic curve would never technically be "done",
|
|
/// but once the difference from the value at a particular time and the
|
|
/// asymptote itself could not be seen, it would be pointless to continue. The
|
|
/// tolerance defines how to determine if the difference could not be seen.
|
|
Tolerance tolerance;
|
|
|
|
@override
|
|
String toString() => '$runtimeType';
|
|
}
|