首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >鼠标滚动不工作在SliverAppbar()或SliverAppbar()浮动不工作颤振网页

鼠标滚动不工作在SliverAppbar()或SliverAppbar()浮动不工作颤振网页
EN

Stack Overflow用户
提问于 2020-07-31 14:36:30
回答 1查看 747关注 0票数 2

当我在CustomScrollView()中使用CustomScrollView()时,SliverAppBar() 浮点:true不适合鼠标滚动

代码语言:javascript
复制
CustomScrollView(

slivers: <Widget>[

  SliverAppBar(
    floating:true,
    expandedHeight: 150.0,
    flexibleSpace: const FlexibleSpaceBar(
      title: Text('Available seats'),
    ),
    actions: <Widget>[
       IconButton(
          icon: const Icon(Icons.add_circle),
          tooltip: 'Add new entry',
          onPressed: () { /* ... */ },
       ),
   ]
  ),
  
  SliverList(
    delegate: SliverChildBuilderDelegate((context, index) {
      return ListTile(
        title: Text('List Tile $index'),
      );
    }, childCount: 100),
  ),
],

),

EN

回答 1

Stack Overflow用户

发布于 2020-07-31 14:36:30

我已经解决了这个问题

创建一个类并根据您的需要给出它的名称。

代码语言:javascript
复制
class SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
  SliverAppBarDelegate({
    @required this.minHeight,
    @required this.maxHeight,
    @required this.child,
  });
  final double minHeight;
  final double maxHeight;
  final Widget child;

  @override
  double get minExtent => minHeight;
  @override
  double get maxExtent => math.max(maxHeight, minHeight);
  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    return SizedBox.expand(child: child);
  }

  @override
  bool shouldRebuild(SliverAppBarDelegate oldDelegate) {
    return maxHeight != oldDelegate.maxHeight ||
        minHeight != oldDelegate.minHeight ||
        child != oldDelegate.child;
  }
}

现在使用类作为SliverAppBar()

代码语言:javascript
复制
CustomScrollView(
        slivers: <Widget>[
//           SliverAppBar(
//             floating: true,
//             snap: true,
//             titleSpacing: 0.0,
//             title: Container(
//               color: Colors.blue,
//             ),
//             elevation: 0,
//             backgroundColor: Theme.of(context).scaffoldBackgroundColor,
//           ),
          SliverPersistentHeader(
            floating: true,
            delegate: SliverAppBarDelegate(
              minHeight: 60,
              maxHeight: 60,
              child: Container(
                color: Colors.red,
                child: Center(
                  child: Text(
                      'I want this to appear only after some scroll offset occured'),
                ),
              ),
            ),
          ),
          SliverPersistentHeader(
            pinned: true,
            delegate: SliverAppBarDelegate(
              minHeight: 60.0,
              maxHeight: 60.0,
              child: Container(
                color: Theme.of(context).scaffoldBackgroundColor,
                child: Column(
                  children: <Widget>[
                    Padding(
                      padding: const EdgeInsets.symmetric(
                        horizontal: 16.0,
                        vertical: 8.0,
                      ),
                      child: Text('Some large text',
                          style: TextStyle(fontSize: 20)),
                    ),
                    Divider(),
                  ],
                ),
              ),
            ),
          ),
          SliverList(
            delegate: SliverChildBuilderDelegate((context, index) {
              return ListTile(
                title: Text('List Tile $index'),
              );
            }, childCount: 100),
          ),
        ],
      ),

或者您可以看到DartPad示例

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63193912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档