import 'package:flutter/material.dart';
/// 隐藏水波纹配置
class NoShadowScrollBehavior extends ScrollBehavior {
Widget buildViewportChrome(
BuildContext context, Widget child, AxisDirection axisDirection) {
switch (getPlatform(context)) {
case TargetPlatform.iOS:
case TargetPlatform.macOS:
return child;
case TargetPlatform.android:
return GlowingOverscrollIndicator(
showLeading: false,
showTrailing: false,
axisDirection: axisDirection,
color: Theme.of(context).colorScheme.secondary,
child: child,
);
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
case TargetPlatform.windows:
return GlowingOverscrollIndicator(
//不显示头部水波纹
showLeading: false,
//不显示尾部水波纹
showTrailing: false,
axisDirection: axisDirection,
color: Theme.of(context).colorScheme.secondary,
child: child,
);
}
}
}
使用:
ScrollConfiguration(
behavior: NoShadowScrollBehavior(),
child: SingleChildScrollView(
),
)
这种方式对所有继承自ScrollView
的widget
都有效,例如ListView
,GridView
, CustomScrollView
, BoxScrollView
)。
THE END