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) {
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) {
var _percentage = ((value - widget.minHeight)) /
(widget.maxHeight - widget.minHeight);
@ -206,8 +214,8 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
},
onPanEnd: (details) async {
///Calculates drag speed
double speed =
(_dragHeight - _startHeight * _dragHeight < _startHeight
double speed = (_dragHeight - _startHeight * _dragHeight <
_startHeight
? 1
: -1) /
updateCount *
@ -268,6 +276,7 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
);
},
valueListenable: heightNotifier,
),
);
}