基础组件库
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

mine_header.dart 1.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. }