【Flutter】二十、Flutter中常用组件—— CustomScrollView

一、CustomScrollView

CustomScrollView是可以使用sliver自定义滚动模型(效果)的widget。其中sliver包括SliverList、SliverFixedExtentList、SliverGrid、SliverPadding、SliverAppBar,对于大多数Sliver来说,它们和可滚动Widget最主要的区别是Sliver不会包含Scrollable Widget,也就是说Sliver本身不包含滚动交互模型。因此,CustomScrollView可以将它们组合起来,统一控制滚动。

示例

import 'package:flutter/material.dart';

class CustomScrollViewDemo extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return CustomScrollView(
      slivers: <Widget>[
        SliverAppBar(
          pinned: true,
          leading: Icon(Icons.arrow_back),
          expandedHeight: 250.0,
          flexibleSpace: FlexibleSpaceBar(
            title: Text('title'),
            background: Image.network('http://pic38.nipic.com/20140228/2457331_083845176000_2.jpg', fit: BoxFit.cover,),
          ),
        ),
        SliverPadding(
          padding: EdgeInsets.all(10.0),
          sliver: SliverGrid(
            delegate: SliverChildBuilderDelegate((context, index) => Container(
              color: Colors.lightBlueAccent,
            ),
                childCount: 15),
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 3,
                mainAxisSpacing: 20.0,
                crossAxisSpacing: 10.0,
                childAspectRatio: 5.0/2.0
            ),
          ),
        ),
        SliverFixedExtentList(
          delegate: SliverChildBuilderDelegate((context, index) => ListTile(
            title: Text('标题$index'),
          ),
              childCount: 10),
          itemExtent: 40.0,
        ),
        SliverList(
          delegate: SliverChildBuilderDelegate((context, index) => ListTile(
            title: Text('标题$index'),
          ),
          childCount: 10),
        ),
      ],
    );
  }
}

效果
在这里插入图片描述

二、Sliver

2.1 SliverAppBar

头部可伸缩widget,屏幕向下滑动时SliverAppBar会自动收缩到一定高度。

属性说明

SliverAppBar({
    Key key,
    this.leading, // 左上方图标
    this.automaticallyImplyLeading = true,
    this.title, // 标题
    this.actions, // 右侧图标组
    this.flexibleSpace, // 设置内容,背景、标题等
    this.bottom,
    this.elevation, // 阴影范围
    this.forceElevated = false, // 是否一致显示阴影,false在展开时不显示阴影
    this.backgroundColor, // 背景色
    this.brightness,
    this.iconTheme, // 图标样式
    this.actionsIconTheme, // 右上角图标样式
    this.textTheme,
    this.primary = true,
    this.centerTitle, // 标题是否居中
    this.titleSpacing = NavigationToolbar.kMiddleSpacing, // 标题距离左侧距离
    this.expandedHeight, // 展开高度
    this.floating = false, // 收缩后是否显示顶部标题栏
    this.pinned = false, // 收缩时是否固定到一定高度
    this.snap = false, 
    this.shape, // 边框设置
  })
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MAXLZ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值