基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

67 lines
1.6 KiB

  1. import 'dart:ui';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. class MineHeaderDelegate extends SliverPersistentHeaderDelegate {
  5. double _height;
  6. MineHeaderDelegate() : super() {
  7. _height = MediaQueryData.fromWindow(window).padding.top + 44;
  8. }
  9. @override
  10. Widget build(
  11. BuildContext context, double shrinkOffset, bool overlapsContent) {
  12. print('${shrinkOffset.toString()}');
  13. double percent = shrinkOffset / _height;
  14. print('${percent.toString()}');
  15. return MineHeader(Colors.red.withOpacity(percent));
  16. }
  17. @override
  18. double get maxExtent => _height;
  19. @override
  20. double get minExtent => _height;
  21. @override
  22. bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) =>
  23. false; // 如果内容需要更新,设置为true
  24. }
  25. class MineHeader extends StatelessWidget {
  26. final Color color;
  27. MineHeader(this.color);
  28. @override
  29. Widget build(BuildContext context) {
  30. return Container(
  31. color: color,
  32. child: Column(
  33. children: <Widget>[
  34. Expanded(child: Container()),
  35. Container(
  36. width: double.infinity,
  37. height: 44,
  38. child: Row(
  39. mainAxisAlignment: MainAxisAlignment.end,
  40. crossAxisAlignment: CrossAxisAlignment.center,
  41. children: <Widget>[
  42. Icon(
  43. Icons.settings,
  44. color: Colors.white,
  45. ),
  46. Icon(
  47. Icons.chat,
  48. color: Colors.white,
  49. )
  50. ],
  51. ),
  52. )
  53. ],
  54. ));
  55. }
  56. }