基础组件库
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.

mine_header_bg_widget.dart 1.7 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import 'package:zhiying_base_widget/pages/main_page/notifier/main_page_bg_notifier.dart';
  4. class MineHeaderBgWidget extends StatefulWidget {
  5. final ScrollController controller;
  6. const MineHeaderBgWidget({Key key, this.controller}) : super(key: key);
  7. @override
  8. _MineHeaderBgWidgetState createState() => _MineHeaderBgWidgetState();
  9. }
  10. class _MineHeaderBgWidgetState extends State<MineHeaderBgWidget> {
  11. int zIndex = 0;
  12. double _offsetY = 0;
  13. double _height = 300;
  14. _MineHeaderBgContainer _content;
  15. @override
  16. void initState() {
  17. super.initState();
  18. _content = _MineHeaderBgContainer();
  19. if (widget.controller != null) {
  20. widget.controller.addListener(() {
  21. if (widget.controller.offset > _height) {
  22. // 减少重绘
  23. return;
  24. }
  25. _offsetY = -widget.controller.offset;
  26. if (_offsetY > 0) {
  27. _offsetY = 0;
  28. }
  29. setState(() {});
  30. });
  31. }
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. return Transform.translate(
  36. offset: Offset(0, _offsetY),
  37. child: _content,
  38. );
  39. }
  40. }
  41. class _MineHeaderBgContainer extends StatefulWidget {
  42. @override
  43. _MineHeaderBgContainerState createState() => _MineHeaderBgContainerState();
  44. }
  45. class _MineHeaderBgContainerState extends State<_MineHeaderBgContainer> {
  46. @override
  47. Widget build(BuildContext context) {
  48. print('_MineHeaderBgContainerState build');
  49. return Consumer<MainPageBgNotifier>(builder: (context, model, widget) {
  50. return Stack(
  51. fit: StackFit.passthrough,
  52. overflow: Overflow.clip,
  53. children: <Widget>[
  54. model.toWidget ?? Container(),
  55. ],
  56. );
  57. });
  58. }
  59. }