|
| 1 | +import 'package:flutter/foundation.dart'; |
1 | 2 | import 'package:flutter/widgets.dart'; |
2 | 3 | import 'package:snapping_sheet/src/above_sheet_size_calculator.dart'; |
3 | 4 | import 'package:snapping_sheet/src/below_sheet_size_calculator.dart'; |
@@ -159,7 +160,7 @@ class SnappingSheet extends StatefulWidget { |
159 | 160 |
|
160 | 161 | class _SnappingSheetState extends State<SnappingSheet> |
161 | 162 | with TickerProviderStateMixin { |
162 | | - double _currentPositionPrivate = 0; |
| 163 | + ValueNotifier<double> _currentPositionPrivate = ValueNotifier(0); |
163 | 164 | BoxConstraints? _latestConstraints; |
164 | 165 | late SnappingPosition _lastSnappingPosition; |
165 | 166 | late AnimationController _animationController; |
@@ -220,11 +221,11 @@ class _SnappingSheetState extends State<SnappingSheet> |
220 | 221 | } |
221 | 222 |
|
222 | 223 | set _currentPosition(double newPosition) { |
223 | | - _currentPositionPrivate = newPosition; |
| 224 | + _currentPositionPrivate.value = newPosition; |
224 | 225 | widget.onSheetMoved?.call(_createPositionData()); |
225 | 226 | } |
226 | 227 |
|
227 | | - double get _currentPosition => _currentPositionPrivate; |
| 228 | + double get _currentPosition => _currentPositionPrivate.value; |
228 | 229 |
|
229 | 230 | SnappingPosition get _initSnappingPosition { |
230 | 231 | return widget.initialSnappingPosition ?? widget.snappingPositions.first; |
@@ -402,7 +403,7 @@ class _SnappingSheetState extends State<SnappingSheet> |
402 | 403 | } |
403 | 404 | } |
404 | 405 |
|
405 | | -class SnappingSheetController { |
| 406 | +class SnappingSheetController implements Listenable { |
406 | 407 | _SnappingSheetState? _state; |
407 | 408 |
|
408 | 409 | /// If a state is attached to this controller. [isAttached] must be true |
@@ -468,4 +469,12 @@ class SnappingSheetController { |
468 | 469 | _checkAttachment(); |
469 | 470 | return _state!._animationController.stop(); |
470 | 471 | } |
| 472 | + |
| 473 | + @override |
| 474 | + void addListener(VoidCallback listener) => |
| 475 | + _state?._currentPositionPrivate.addListener(listener); |
| 476 | + |
| 477 | + @override |
| 478 | + void removeListener(VoidCallback listener) => |
| 479 | + _state?._currentPositionPrivate.removeListener(listener); |
471 | 480 | } |
0 commit comments