解决更新完Flutter版本后报错The method 'buildViewportChrome' isn't defined in a superclass of 'CusBehavior'
提示
参考文档: https://docs.flutter.dev/release/breaking-changes/3-3-deprecations#scrollbehaviorbuildviewportchrome
问题原因:
方法
ScrollBehavior.buildViewportChrome
已在v2.1
中弃用。
解决方式:
使用
buildOverscrollIndicator
代替buildViewportChrome
方法
修改前的代码
class CusBehavior extends ScrollBehavior {
@override
Widget buildViewportChrome(
BuildContext context, Widget child, AxisDirection axisDirection) {
if (Platform.isAndroid || Platform.isFuchsia) return child;
return super.buildViewportChrome(context, child, axisDirection);
}
}
修改后的代码
class CusBehavior extends ScrollBehavior {
@override
Widget buildOverscrollIndicator(
BuildContext context, Widget child, ScrollableDetails details) {
if (Platform.isAndroid || Platform.isFuchsia) return child;
return super.buildOverscrollIndicator(context, child, details);
}
}
个人博客:https://www.linmeimei.top/ 欢迎访问