transitions.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import 'package:flutter/widgets.dart';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/rendering.dart';
  4. class SizeTransitionWithIntrinsicSize extends SingleChildRenderObjectWidget {
  5. /// Creates a size transition with its intrinsic width/height taking [sizeFactor]
  6. /// into account.
  7. ///
  8. /// The [axis] argument defaults to [Axis.vertical].
  9. /// The [axisAlignment] defaults to 0.0, which centers the child along the
  10. /// main axis during the transition.
  11. SizeTransitionWithIntrinsicSize({
  12. this.axis = Axis.vertical,
  13. required this.sizeFactor,
  14. double axisAlignment = 0.0,
  15. Widget? child,
  16. Key? key,
  17. }) : super(
  18. key: key,
  19. child: SizeTransition(
  20. axis: axis,
  21. sizeFactor: sizeFactor,
  22. axisAlignment: axisAlignment,
  23. child: child,
  24. ));
  25. final Axis axis;
  26. final Animation<double> sizeFactor;
  27. @override
  28. RenderSizeTransitionWithIntrinsicSize createRenderObject(
  29. BuildContext context) {
  30. return RenderSizeTransitionWithIntrinsicSize(
  31. axis: axis,
  32. sizeFactor: sizeFactor,
  33. );
  34. }
  35. @override
  36. void updateRenderObject(BuildContext context,
  37. RenderSizeTransitionWithIntrinsicSize renderObject) {
  38. renderObject
  39. ..axis = axis
  40. ..sizeFactor = sizeFactor;
  41. }
  42. @override
  43. void debugFillProperties(DiagnosticPropertiesBuilder properties) {
  44. super.debugFillProperties(properties);
  45. properties.add(DiagnosticsProperty<Axis>('axis', axis));
  46. properties
  47. .add(DiagnosticsProperty<Animation<double>>('sizeFactor', sizeFactor));
  48. }
  49. }
  50. class RenderSizeTransitionWithIntrinsicSize extends RenderProxyBox {
  51. Axis axis;
  52. Animation<double> sizeFactor;
  53. RenderSizeTransitionWithIntrinsicSize({
  54. this.axis = Axis.vertical,
  55. required this.sizeFactor,
  56. RenderBox? child,
  57. }) : super(child);
  58. @override
  59. double computeMinIntrinsicWidth(double height) {
  60. final child = this.child;
  61. if (child != null) {
  62. double childWidth = child.getMinIntrinsicWidth(height);
  63. return axis == Axis.horizontal
  64. ? childWidth * sizeFactor.value
  65. : childWidth;
  66. }
  67. return 0.0;
  68. }
  69. @override
  70. double computeMaxIntrinsicWidth(double height) {
  71. final child = this.child;
  72. if (child != null) {
  73. double childWidth = child.getMaxIntrinsicWidth(height);
  74. return axis == Axis.horizontal
  75. ? childWidth * sizeFactor.value
  76. : childWidth;
  77. }
  78. return 0.0;
  79. }
  80. @override
  81. double computeMinIntrinsicHeight(double width) {
  82. final child = this.child;
  83. if (child != null) {
  84. double childHeight = child.getMinIntrinsicHeight(width);
  85. return axis == Axis.vertical
  86. ? childHeight * sizeFactor.value
  87. : childHeight;
  88. }
  89. return 0.0;
  90. }
  91. @override
  92. double computeMaxIntrinsicHeight(double width) {
  93. final child = this.child;
  94. if (child != null) {
  95. double childHeight = child.getMaxIntrinsicHeight(width);
  96. return axis == Axis.vertical
  97. ? childHeight * sizeFactor.value
  98. : childHeight;
  99. }
  100. return 0.0;
  101. }
  102. }