Remove ScrollBehavior.getGlowColor (#9145)
This method seemed overly specific to the needs of one particular subclass. This patch duplicates some code but makes the API conceptually cleaner. Fixes #8267
This commit is contained in:
parent
20015400f9
commit
f00b3a4b06
@ -174,8 +174,21 @@ class _MaterialScrollBehavior extends ScrollBehavior {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Color getGlowColor(BuildContext context) {
|
Widget buildViewportChrome(BuildContext context, Widget child, AxisDirection axisDirection) {
|
||||||
return Theme.of(context).accentColor;
|
// When modifying this function, consider modifying the implementation in
|
||||||
|
// the base class as well.
|
||||||
|
switch (getPlatform(context)) {
|
||||||
|
case TargetPlatform.iOS:
|
||||||
|
return child;
|
||||||
|
case TargetPlatform.android:
|
||||||
|
case TargetPlatform.fuchsia:
|
||||||
|
return new GlowingOverscrollIndicator(
|
||||||
|
child: child,
|
||||||
|
axisDirection: axisDirection,
|
||||||
|
color: Theme.of(context).accentColor,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,14 @@ import 'framework.dart';
|
|||||||
import 'overscroll_indicator.dart';
|
import 'overscroll_indicator.dart';
|
||||||
import 'scroll_physics.dart';
|
import 'scroll_physics.dart';
|
||||||
|
|
||||||
|
const Color _kDefaultGlowColor = const Color(0xFFFFFFFF);
|
||||||
|
|
||||||
|
/// Describes how [Scrollable] widgets should behave.
|
||||||
|
///
|
||||||
|
/// Used by [ScrollConfiguration] to configure the [Scrollable] widgets in a
|
||||||
|
/// subtree.
|
||||||
class ScrollBehavior {
|
class ScrollBehavior {
|
||||||
|
/// Creates a description of how [Scrollable] widgets should behave.
|
||||||
const ScrollBehavior();
|
const ScrollBehavior();
|
||||||
|
|
||||||
/// The platform whose scroll physics should be implemented.
|
/// The platform whose scroll physics should be implemented.
|
||||||
@ -17,13 +24,14 @@ class ScrollBehavior {
|
|||||||
/// Defaults to the current platform.
|
/// Defaults to the current platform.
|
||||||
TargetPlatform getPlatform(BuildContext context) => defaultTargetPlatform;
|
TargetPlatform getPlatform(BuildContext context) => defaultTargetPlatform;
|
||||||
|
|
||||||
/// The color to use for the glow effect when [platform] indicates a platform
|
/// Wraps the given widget, which scrolls in the given [AxisDirection].
|
||||||
/// that uses a [GlowingOverscrollIndicator].
|
|
||||||
///
|
///
|
||||||
/// Defaults to white.
|
/// For example, on Android, this method wraps the given widget with a
|
||||||
Color getGlowColor(BuildContext context) => const Color(0xFFFFFFFF);
|
/// [GlowingOverscrollIndicator] to provide visual feedback when the user
|
||||||
|
/// overscrolls.
|
||||||
Widget buildViewportChrome(BuildContext context, Widget child, AxisDirection axisDirection) {
|
Widget buildViewportChrome(BuildContext context, Widget child, AxisDirection axisDirection) {
|
||||||
|
// When modifying this function, consider modifying the implementation in
|
||||||
|
// _MaterialScrollBehavior as well.
|
||||||
switch (getPlatform(context)) {
|
switch (getPlatform(context)) {
|
||||||
case TargetPlatform.iOS:
|
case TargetPlatform.iOS:
|
||||||
return child;
|
return child;
|
||||||
@ -32,7 +40,7 @@ class ScrollBehavior {
|
|||||||
return new GlowingOverscrollIndicator(
|
return new GlowingOverscrollIndicator(
|
||||||
child: child,
|
child: child,
|
||||||
axisDirection: axisDirection,
|
axisDirection: axisDirection,
|
||||||
color: getGlowColor(context),
|
color: _kDefaultGlowColor,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -56,15 +64,24 @@ class ScrollBehavior {
|
|||||||
bool shouldNotify(covariant ScrollBehavior oldDelegate) => false;
|
bool shouldNotify(covariant ScrollBehavior oldDelegate) => false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Controls how [Scrollable] widgets behave in a subtree.
|
||||||
|
///
|
||||||
|
/// The scroll configuration determines the [ScrollPhysics] and viewport
|
||||||
|
/// decorations used by decendants of [child].
|
||||||
class ScrollConfiguration extends InheritedWidget {
|
class ScrollConfiguration extends InheritedWidget {
|
||||||
|
/// Creates a widget that controls how [Scrollable] widgets behave in a subtree.
|
||||||
|
///
|
||||||
|
/// The [behavior] and [child] arguments must not be null.
|
||||||
const ScrollConfiguration({
|
const ScrollConfiguration({
|
||||||
Key key,
|
Key key,
|
||||||
@required this.behavior,
|
@required this.behavior,
|
||||||
@required Widget child,
|
@required Widget child,
|
||||||
}) : super(key: key, child: child);
|
}) : super(key: key, child: child);
|
||||||
|
|
||||||
|
/// How [Scrollable] widgets that are decendants of [child] should behave.
|
||||||
final ScrollBehavior behavior;
|
final ScrollBehavior behavior;
|
||||||
|
|
||||||
|
/// The [ScrollBehavior] for [Scrollable] widgets in the given [BuildContext].
|
||||||
static ScrollBehavior of(BuildContext context) {
|
static ScrollBehavior of(BuildContext context) {
|
||||||
final ScrollConfiguration configuration = context.inheritFromWidgetOfExactType(ScrollConfiguration);
|
final ScrollConfiguration configuration = context.inheritFromWidgetOfExactType(ScrollConfiguration);
|
||||||
return configuration?.behavior ?? const ScrollBehavior();
|
return configuration?.behavior ?? const ScrollBehavior();
|
||||||
|
@ -267,14 +267,22 @@ void main() {
|
|||||||
|
|
||||||
class TestScrollBehavior1 extends ScrollBehavior {
|
class TestScrollBehavior1 extends ScrollBehavior {
|
||||||
@override
|
@override
|
||||||
Color getGlowColor(BuildContext context) {
|
Widget buildViewportChrome(BuildContext context, Widget child, AxisDirection axisDirection) {
|
||||||
return const Color(0xFF00FF00);
|
return new GlowingOverscrollIndicator(
|
||||||
|
child: child,
|
||||||
|
axisDirection: axisDirection,
|
||||||
|
color: const Color(0xFF00FF00),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestScrollBehavior2 extends ScrollBehavior {
|
class TestScrollBehavior2 extends ScrollBehavior {
|
||||||
@override
|
@override
|
||||||
Color getGlowColor(BuildContext context) {
|
Widget buildViewportChrome(BuildContext context, Widget child, AxisDirection axisDirection) {
|
||||||
return const Color(0xFF0000FF);
|
return new GlowingOverscrollIndicator(
|
||||||
|
child: child,
|
||||||
|
axisDirection: axisDirection,
|
||||||
|
color: const Color(0xFF0000FF),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user