我正在尝试改变滚动glov的位置,从顶部到底部的appBar内部的CustomScrollView。根据官方文档中的示例,我可以使用NotificationListener。但是当我尝试在我的代码中实现它时,notification.paintOffset没有定义。我应该怎么做,下面是我的代码:
class HomeView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: _buildContent(context),
);
}
Widget _buildContent(BuildContext context) {
double leadingPaintOffset = MediaQuery.of(context).padding.top + AppBar().preferredSize.height;
return NotificationListener<OverscrollIndicatorNotification>(
onNotification: (notification) {
if (notification.leading) {
notification.paintOffset = leadingPaintOffset;
}
return false;
},
child: CustomScrollView(
slivers: [
SliverAppBar(title: Text('Custom PaintOffset')),
SliverToBoxAdapter(
child: Container(
color: Colors.amberAccent,
height: 100,
child: Center(child: Text('Glow all day!')),
),
),
SliverFillRemaining(child: FlutterLogo()),
],
),
);
}
}下面是一个例外:
The setter 'paintOffset' isn't defined for the class 'OverscrollIndicatorNotification'.
Try importing the library that defines 'paintOffset', correcting the name to the name of an existing setter, or defining a setter or field named 'paintOffset'.所以,notification.paintOffset没有定义!求求你救命!这是官方文档的链接:https://api.flutter.dev/flutter/widgets/GlowingOverscrollIndicator-class.html
下面是Flutter doctor的输出:
√] Flutter (Channel stable, v1.12.13+hotfix.8, ...)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[!] Android Studio (version 3.5)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[√] VS Code (version 1.47.3)
[!] Connected device
! No devices available
! Doctor found issues in 2 categories.

谢谢!
发布于 2020-08-14 13:42:48
3个月前在this commit中引入了paintOffset
您将不会在以前的flutter版本(如您的v1.12.13)中找到它的定义。尝试将flutter升级到至少1.17.1,因为它是在2020年5月13日合并的
https://stackoverflow.com/questions/63406776
复制相似问题