【发布时间】:2020-12-03 23:42:45
【问题描述】:
我正在尝试在 CustomScrollView 内从 appBar 的顶部到底部更改滚动手套的位置。根据官方文档中的示例,我可以使用 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 医生的输出:
√] 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.
谢谢!
【问题讨论】:
-
您可以尝试重新提出您的问题吗?
-
到底有什么不清楚的地方?
-
很遗憾,我的英语语言不太好))
-
好的,问题是
notification.paintOffset属性设置不正确? -
是的...在代码中应用时没有定义!