import 'dart:ui'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class MineHeaderDelegate extends SliverPersistentHeaderDelegate { double _height; MineHeaderDelegate() : super() { _height = MediaQueryData.fromWindow(window).padding.top + 44; } @override Widget build( BuildContext context, double shrinkOffset, bool overlapsContent) { print('${shrinkOffset.toString()}'); double percent = shrinkOffset / _height; print('${percent.toString()}'); return MineHeader(Colors.red.withOpacity(percent)); } @override double get maxExtent => _height; @override double get minExtent => _height; @override bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) => false; // 如果内容需要更新,设置为true } class MineHeader extends StatelessWidget { final Color color; MineHeader(this.color); @override Widget build(BuildContext context) { return Container( color: color, child: Column( children: [ Expanded(child: Container()), Container( width: double.infinity, height: 44, child: Row( mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.center, children: [ Icon( Icons.settings, color: Colors.white, ), Icon( Icons.chat, color: Colors.white, ) ], ), ) ], )); } }