mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-24 20:35:50 +08:00
improve Dyn/Topic DraggableScrollableSheet
Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
91
lib/common/widgets/draggable_sheet/dyn.dart
Normal file
91
lib/common/widgets/draggable_sheet/dyn.dart
Normal file
@@ -0,0 +1,91 @@
|
||||
part of 'package:PiliPlus/common/widgets/flutter/draggable_scrollable_sheet.dart';
|
||||
|
||||
class DynDraggableScrollableSheet extends DraggableScrollableSheet {
|
||||
const DynDraggableScrollableSheet({
|
||||
super.key,
|
||||
super.initialChildSize,
|
||||
super.minChildSize,
|
||||
super.maxChildSize,
|
||||
super.expand,
|
||||
super.snap,
|
||||
super.snapSizes,
|
||||
super.snapAnimationDuration,
|
||||
super.controller,
|
||||
super.shouldCloseOnMinExtent,
|
||||
required super.builder,
|
||||
});
|
||||
|
||||
@override
|
||||
State<DraggableScrollableSheet> createState() =>
|
||||
_DynDraggableScrollableSheetState();
|
||||
}
|
||||
|
||||
class _DynDraggableScrollableSheetState extends _DraggableScrollableSheetState {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_extent = _DraggableSheetExtent(
|
||||
minSize: widget.minChildSize,
|
||||
maxSize: widget.maxChildSize,
|
||||
snap: widget.snap,
|
||||
snapSizes: _impliedSnapSizes(),
|
||||
snapAnimationDuration: widget.snapAnimationDuration,
|
||||
initialSize: widget.initialChildSize,
|
||||
shouldCloseOnMinExtent: widget.shouldCloseOnMinExtent,
|
||||
);
|
||||
_scrollController = _DynDraggableScrollableSheetScrollController(
|
||||
extent: _extent,
|
||||
);
|
||||
widget.controller?._attach(_scrollController);
|
||||
}
|
||||
}
|
||||
|
||||
class _DynDraggableScrollableSheetScrollController
|
||||
extends _DraggableScrollableSheetScrollController {
|
||||
_DynDraggableScrollableSheetScrollController({
|
||||
required super.extent,
|
||||
});
|
||||
|
||||
@override
|
||||
_DraggableScrollableSheetScrollPosition createScrollPosition(
|
||||
ScrollPhysics physics,
|
||||
ScrollContext context,
|
||||
ScrollPosition? oldPosition,
|
||||
) {
|
||||
return _DynDraggableScrollableSheetScrollPosition(
|
||||
physics: physics.applyTo(const AlwaysScrollableScrollPhysics()),
|
||||
context: context,
|
||||
oldPosition: oldPosition,
|
||||
getExtent: () => extent,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DynDraggableScrollableSheetScrollPosition
|
||||
extends _DraggableScrollableSheetScrollPosition {
|
||||
_DynDraggableScrollableSheetScrollPosition({
|
||||
required super.physics,
|
||||
required super.context,
|
||||
super.oldPosition,
|
||||
required super.getExtent,
|
||||
});
|
||||
|
||||
bool _isAtTop = true;
|
||||
|
||||
@override
|
||||
bool get listShouldScroll => !_isAtTop || super.listShouldScroll;
|
||||
|
||||
@override
|
||||
void applyUserOffset(double delta) {
|
||||
if (_isAtTop && pixels > 0) {
|
||||
_isAtTop = false;
|
||||
}
|
||||
super.applyUserOffset(delta);
|
||||
}
|
||||
|
||||
@override
|
||||
Drag drag(DragStartDetails details, VoidCallback dragCancelCallback) {
|
||||
_isAtTop = pixels == 0;
|
||||
return super.drag(details, dragCancelCallback);
|
||||
}
|
||||
}
|
||||
74
lib/common/widgets/draggable_sheet/topic.dart
Normal file
74
lib/common/widgets/draggable_sheet/topic.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
part of 'package:PiliPlus/common/widgets/flutter/draggable_scrollable_sheet.dart';
|
||||
|
||||
class TopicDraggableScrollableSheet extends DraggableScrollableSheet {
|
||||
const TopicDraggableScrollableSheet({
|
||||
super.key,
|
||||
super.initialChildSize,
|
||||
super.minChildSize,
|
||||
super.maxChildSize,
|
||||
super.expand,
|
||||
super.snap,
|
||||
super.snapSizes,
|
||||
super.snapAnimationDuration,
|
||||
super.controller,
|
||||
super.shouldCloseOnMinExtent,
|
||||
required super.builder,
|
||||
this.initialScrollOffset = 0.0,
|
||||
});
|
||||
|
||||
final double initialScrollOffset;
|
||||
|
||||
@override
|
||||
State<DraggableScrollableSheet> createState() =>
|
||||
_TopicDraggableScrollableSheetState();
|
||||
}
|
||||
|
||||
class _TopicDraggableScrollableSheetState
|
||||
extends _DraggableScrollableSheetState {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_extent = _DraggableSheetExtent(
|
||||
minSize: widget.minChildSize,
|
||||
maxSize: widget.maxChildSize,
|
||||
snap: widget.snap,
|
||||
snapSizes: _impliedSnapSizes(),
|
||||
snapAnimationDuration: widget.snapAnimationDuration,
|
||||
initialSize: widget.initialChildSize,
|
||||
shouldCloseOnMinExtent: widget.shouldCloseOnMinExtent,
|
||||
);
|
||||
_scrollController = _TopicDraggableScrollableSheetScrollController(
|
||||
extent: _extent,
|
||||
initialScrollOffset:
|
||||
(widget as TopicDraggableScrollableSheet).initialScrollOffset,
|
||||
);
|
||||
widget.controller?._attach(_scrollController);
|
||||
}
|
||||
}
|
||||
|
||||
class _TopicDraggableScrollableSheetScrollController
|
||||
extends _DraggableScrollableSheetScrollController {
|
||||
_TopicDraggableScrollableSheetScrollController({
|
||||
required super.extent,
|
||||
double initialScrollOffset = 0.0,
|
||||
}) : _initialScrollOffset = initialScrollOffset;
|
||||
|
||||
@override
|
||||
double get initialScrollOffset => _initialScrollOffset;
|
||||
final double _initialScrollOffset;
|
||||
|
||||
@override
|
||||
_DraggableScrollableSheetScrollPosition createScrollPosition(
|
||||
ScrollPhysics physics,
|
||||
ScrollContext context,
|
||||
ScrollPosition? oldPosition,
|
||||
) {
|
||||
return _DraggableScrollableSheetScrollPosition(
|
||||
physics: physics.applyTo(const AlwaysScrollableScrollPhysics()),
|
||||
context: context,
|
||||
oldPosition: oldPosition,
|
||||
getExtent: () => extent,
|
||||
initialPixels: _initialScrollOffset,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user