【问题标题】:Change position of glov of CustomScrollView改变 CustomScrollView 手套的位置
【发布时间】: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 属性设置不正确?
  • 是的...在代码中应用时没有定义!

标签: flutter dart


【解决方案1】:

paintOffset 是 3 个月前在 this commit 中介绍的

你不会发现它在以前的颤振版本中定义(比如你的 v1.12.13)。自 2020 年 5 月 13 日合并以来,请尝试将您的 Flutter 至少升级到 1.17.1

【讨论】:

  • 他们没有写任何关于 Flutter 版本兼容性的文章..
  • 非常感谢,我会尝试更新flutter版本
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-11-02
  • 2019-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-31
  • 2014-07-11
相关资源
最近更新 更多