Committed by
GitHub
Fix update Sheet content while initializing (#432)
Showing
3 changed files
with
21 additions
and
4 deletions
@@ -373,11 +373,18 @@ class __SheetRouteContainerState extends State<_SheetRouteContainer> | @@ -373,11 +373,18 @@ class __SheetRouteContainerState extends State<_SheetRouteContainer> | ||
373 | _routeController.addListener(onRouteAnimationUpdate); | 373 | _routeController.addListener(onRouteAnimationUpdate); |
374 | _sheetController.addListener(onSheetExtentUpdate); | 374 | _sheetController.addListener(onSheetExtentUpdate); |
375 | WidgetsBinding.instance.addPostFrameCallback((Duration timeStamp) { | 375 | WidgetsBinding.instance.addPostFrameCallback((Duration timeStamp) { |
376 | - _sheetController.relativeAnimateTo( | 376 | + _sheetController |
377 | + .relativeAnimateTo( | ||
377 | route.initialExtent, | 378 | route.initialExtent, |
378 | duration: route.transitionDuration, | 379 | duration: route.transitionDuration, |
379 | curve: route.animationCurve ?? Curves.easeOut, | 380 | curve: route.animationCurve ?? Curves.easeOut, |
380 | - ); | 381 | + ) |
382 | + .then((_) { | ||
383 | + if (_sheetController.hasClients) { | ||
384 | + (_sheetController.position.context as SheetContext) | ||
385 | + .initialAnimationFinished = true; | ||
386 | + } | ||
387 | + }); | ||
381 | }); | 388 | }); |
382 | super.initState(); | 389 | super.initState(); |
383 | } | 390 | } |
@@ -122,7 +122,12 @@ class SheetPrimaryScrollPosition extends ScrollPositionWithSingleContext { | @@ -122,7 +122,12 @@ class SheetPrimaryScrollPosition extends ScrollPositionWithSingleContext { | ||
122 | } | 122 | } |
123 | 123 | ||
124 | if (sheetPosition.hasContentDimensions) { | 124 | if (sheetPosition.hasContentDimensions) { |
125 | - sheetPosition.goBallistic(velocity); | 125 | + if (sheetContext.initialAnimationFinished) { |
126 | + sheetPosition.goBallistic(velocity); | ||
127 | + } else { | ||
128 | + goIdle(); | ||
129 | + return; | ||
130 | + } | ||
126 | } | 131 | } |
127 | 132 | ||
128 | if (velocity > 0.0 && | 133 | if (velocity > 0.0 && |
@@ -25,6 +25,8 @@ import 'package:sheet/src/widgets/min_interaction.dart'; | @@ -25,6 +25,8 @@ import 'package:sheet/src/widgets/min_interaction.dart'; | ||
25 | abstract class SheetContext extends ScrollContext { | 25 | abstract class SheetContext extends ScrollContext { |
26 | double? get initialExtent; | 26 | double? get initialExtent; |
27 | SheetPosition get position; | 27 | SheetPosition get position; |
28 | + bool get initialAnimationFinished; | ||
29 | + set initialAnimationFinished(bool initialAnimationFinished); | ||
28 | } | 30 | } |
29 | 31 | ||
30 | /// A widget that transform to user drag. | 32 | /// A widget that transform to user drag. |
@@ -326,6 +328,9 @@ class SheetState extends State<SheetScrollable> | @@ -326,6 +328,9 @@ class SheetState extends State<SheetScrollable> | ||
326 | @override | 328 | @override |
327 | AxisDirection get axisDirection => widget.axisDirection; | 329 | AxisDirection get axisDirection => widget.axisDirection; |
328 | 330 | ||
331 | + @override | ||
332 | + bool initialAnimationFinished = false; | ||
333 | + | ||
329 | late SheetBehavior _configuration; | 334 | late SheetBehavior _configuration; |
330 | ScrollPhysics? _physics; | 335 | ScrollPhysics? _physics; |
331 | SheetController? _fallbackScrollController; | 336 | SheetController? _fallbackScrollController; |
@@ -775,7 +780,7 @@ class _ScrollSemantics extends SingleChildRenderObjectWidget { | @@ -775,7 +780,7 @@ class _ScrollSemantics extends SingleChildRenderObjectWidget { | ||
775 | required this.allowImplicitScrolling, | 780 | required this.allowImplicitScrolling, |
776 | required this.semanticChildCount, | 781 | required this.semanticChildCount, |
777 | super.child, | 782 | super.child, |
778 | - }) : assert(semanticChildCount == null || semanticChildCount >= 0); | 783 | + }) : assert(semanticChildCount == null || semanticChildCount >= 0); |
779 | 784 | ||
780 | final ScrollPosition position; | 785 | final ScrollPosition position; |
781 | final bool allowImplicitScrolling; | 786 | final bool allowImplicitScrolling; |
-
Please register or login to post a comment