基础组件库
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

81 lines
2.0 KiB

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