Added WillPopScope

This commit is contained in:
David 2020-12-15 13:14:16 +01:00
parent d99551203d
commit 6918f18f8a
1 changed files with 126 additions and 117 deletions

View File

@ -142,7 +142,15 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (dismissed) return Container(); if (dismissed) return Container();
return ValueListenableBuilder( return WillPopScope(
onWillPop: () async {
if (heightNotifier.value > widget.minHeight) {
_snapToPosition(PanelState.MIN);
return false;
}
return true;
},
child: ValueListenableBuilder(
builder: (BuildContext context, double value, Widget child) { builder: (BuildContext context, double value, Widget child) {
var _percentage = ((value - widget.minHeight)) / var _percentage = ((value - widget.minHeight)) /
(widget.maxHeight - widget.minHeight); (widget.maxHeight - widget.minHeight);
@ -206,8 +214,8 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
}, },
onPanEnd: (details) async { onPanEnd: (details) async {
///Calculates drag speed ///Calculates drag speed
double speed = double speed = (_dragHeight - _startHeight * _dragHeight <
(_dragHeight - _startHeight * _dragHeight < _startHeight _startHeight
? 1 ? 1
: -1) / : -1) /
updateCount * updateCount *
@ -268,6 +276,7 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
); );
}, },
valueListenable: heightNotifier, valueListenable: heightNotifier,
),
); );
} }