Use curly brackets
This commit is contained in:
parent
93e82a73f6
commit
8358e625a5
|
@ -98,7 +98,9 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _resetAnimationController({Duration? duration}) {
|
void _resetAnimationController({Duration? duration}) {
|
||||||
if (_animationController != null) _animationController!.dispose();
|
if (_animationController != null) {
|
||||||
|
_animationController!.dispose();
|
||||||
|
}
|
||||||
_animationController = AnimationController(
|
_animationController = AnimationController(
|
||||||
vsync: this,
|
vsync: this,
|
||||||
duration: duration ?? widget.duration,
|
duration: duration ?? widget.duration,
|
||||||
|
@ -109,23 +111,26 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
if (widget.valueNotifier == null)
|
if (widget.valueNotifier == null) {
|
||||||
heightNotifier = ValueNotifier(widget.minHeight);
|
heightNotifier = ValueNotifier(widget.minHeight);
|
||||||
else
|
} else {
|
||||||
heightNotifier = widget.valueNotifier!;
|
heightNotifier = widget.valueNotifier!;
|
||||||
|
}
|
||||||
|
|
||||||
_resetAnimationController();
|
_resetAnimationController();
|
||||||
|
|
||||||
_dragHeight = heightNotifier.value;
|
_dragHeight = heightNotifier.value;
|
||||||
|
|
||||||
if (widget.controller != null)
|
if (widget.controller != null) {
|
||||||
widget.controller!.addListener(controllerListener);
|
widget.controller!.addListener(controllerListener);
|
||||||
|
}
|
||||||
|
|
||||||
if (widget.onDismissed != null)
|
if (widget.onDismissed != null) {
|
||||||
onDismissed = widget.onDismissed;
|
onDismissed = widget.onDismissed;
|
||||||
else
|
} else {
|
||||||
// ignore: deprecated_member_use_from_same_package
|
// ignore: deprecated_member_use_from_same_package
|
||||||
onDismissed = widget.onDismiss;
|
onDismissed = widget.onDismiss;
|
||||||
|
}
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
@ -133,17 +138,23 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_heightController.close();
|
_heightController.close();
|
||||||
if (_animationController != null) _animationController!.dispose();
|
|
||||||
|
|
||||||
if (widget.controller != null)
|
if (_animationController != null) {
|
||||||
|
_animationController!.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (widget.controller != null) {
|
||||||
widget.controller!.removeListener(controllerListener);
|
widget.controller!.removeListener(controllerListener);
|
||||||
|
}
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (dismissed) return Container();
|
if (dismissed) {
|
||||||
|
return Container();
|
||||||
|
}
|
||||||
|
|
||||||
return MiniplayerWillPopScope(
|
return MiniplayerWillPopScope(
|
||||||
onWillPop: () async {
|
onWillPop: () async {
|
||||||
|
@ -216,7 +227,9 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
|
||||||
_startHeight = _dragHeight;
|
_startHeight = _dragHeight;
|
||||||
updateCount = 0;
|
updateCount = 0;
|
||||||
|
|
||||||
if (animating) _resetAnimationController();
|
if (animating) {
|
||||||
|
_resetAnimationController();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onPanEnd: (details) async {
|
onPanEnd: (details) async {
|
||||||
///Calculates drag speed
|
///Calculates drag speed
|
||||||
|
@ -229,11 +242,13 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
|
||||||
|
|
||||||
///Define the percentage distance depending on the speed with which the widget should snap
|
///Define the percentage distance depending on the speed with which the widget should snap
|
||||||
double snapPercentage = 0.005;
|
double snapPercentage = 0.005;
|
||||||
if (speed <= 4)
|
if (speed <= 4) {
|
||||||
snapPercentage = 0.2;
|
snapPercentage = 0.2;
|
||||||
else if (speed <= 9)
|
} else if (speed <= 9) {
|
||||||
snapPercentage = 0.08;
|
snapPercentage = 0.08;
|
||||||
else if (speed <= 50) snapPercentage = 0.01;
|
} else if (speed <= 50) {
|
||||||
|
snapPercentage = 0.01;
|
||||||
|
}
|
||||||
|
|
||||||
///Determine to which SnapPosition the widget should snap
|
///Determine to which SnapPosition the widget should snap
|
||||||
PanelState snap = PanelState.MIN;
|
PanelState snap = PanelState.MIN;
|
||||||
|
@ -245,23 +260,27 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
|
||||||
|
|
||||||
///Started from expanded state
|
///Started from expanded state
|
||||||
if (_startHeight > widget.minHeight) {
|
if (_startHeight > widget.minHeight) {
|
||||||
if (_percentageMax > 1 - snapPercentage)
|
if (_percentageMax > 1 - snapPercentage) {
|
||||||
snap = PanelState.MAX;
|
snap = PanelState.MAX;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///Started from minified state
|
///Started from minified state
|
||||||
else {
|
else {
|
||||||
if (_percentageMax > snapPercentage)
|
if (_percentageMax > snapPercentage) {
|
||||||
snap = PanelState.MAX;
|
snap = PanelState.MAX;
|
||||||
else
|
}
|
||||||
|
|
||||||
///DismissedPercentage > 0.2 -> dismiss
|
///DismissedPercentage > 0.2 -> dismiss
|
||||||
if (onDismissed != null &&
|
else if (onDismissed != null &&
|
||||||
percentageFromValueInRange(
|
percentageFromValueInRange(
|
||||||
min: widget.minHeight,
|
min: widget.minHeight,
|
||||||
max: 0,
|
max: 0,
|
||||||
value: _dragHeight) >
|
value: _dragHeight,
|
||||||
snapPercentage) snap = PanelState.DISMISS;
|
) >
|
||||||
|
snapPercentage) {
|
||||||
|
snap = PanelState.DISMISS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///Snap to position
|
///Snap to position
|
||||||
|
@ -289,7 +308,9 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
|
||||||
void _handleHeightChange({bool animation = false}) {
|
void _handleHeightChange({bool animation = false}) {
|
||||||
///Drag above minHeight
|
///Drag above minHeight
|
||||||
if (_dragHeight >= widget.minHeight) {
|
if (_dragHeight >= widget.minHeight) {
|
||||||
if (dragDownPercentage.value != 0) dragDownPercentage.value = 0;
|
if (dragDownPercentage.value != 0) {
|
||||||
|
dragDownPercentage.value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (_dragHeight > widget.maxHeight) return;
|
if (_dragHeight > widget.maxHeight) return;
|
||||||
|
|
||||||
|
@ -298,20 +319,21 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
|
||||||
|
|
||||||
///Drag below minHeight
|
///Drag below minHeight
|
||||||
else if (onDismissed != null) {
|
else if (onDismissed != null) {
|
||||||
var percentageDown = borderDouble(
|
final percentageDown = borderDouble(
|
||||||
minRange: 0.0,
|
minRange: 0.0,
|
||||||
maxRange: 1.0,
|
maxRange: 1.0,
|
||||||
value: percentageFromValueInRange(
|
value: percentageFromValueInRange(
|
||||||
min: widget.minHeight, max: 0, value: _dragHeight));
|
min: widget.minHeight, max: 0, value: _dragHeight));
|
||||||
|
|
||||||
if (dragDownPercentage.value != percentageDown)
|
if (dragDownPercentage.value != percentageDown) {
|
||||||
dragDownPercentage.value = percentageDown;
|
dragDownPercentage.value = percentageDown;
|
||||||
|
}
|
||||||
|
|
||||||
if (percentageDown >= 1 && animation && !dismissed) {
|
if (percentageDown >= 1 && animation && !dismissed) {
|
||||||
if (onDismissed != null) onDismissed!();
|
if (onDismissed != null) {
|
||||||
setState(() {
|
onDismissed!();
|
||||||
dismissed = true;
|
}
|
||||||
});
|
setState(() => dismissed = true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,7 +358,9 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
|
||||||
if (_animationController == null) return;
|
if (_animationController == null) return;
|
||||||
final startHeight = _dragHeight;
|
final startHeight = _dragHeight;
|
||||||
|
|
||||||
if (duration != null) _resetAnimationController(duration: duration);
|
if (duration != null) {
|
||||||
|
_resetAnimationController(duration: duration);
|
||||||
|
}
|
||||||
|
|
||||||
Animation<double> _sizeAnimation = Tween(
|
Animation<double> _sizeAnimation = Tween(
|
||||||
begin: startHeight,
|
begin: startHeight,
|
||||||
|
@ -408,22 +432,26 @@ class MiniplayerController extends ValueNotifier<ControllerData?> {
|
||||||
//Animates to a given height or state(expanded, dismissed, ...)
|
//Animates to a given height or state(expanded, dismissed, ...)
|
||||||
void animateToHeight(
|
void animateToHeight(
|
||||||
{double? height, PanelState? state, Duration? duration}) {
|
{double? height, PanelState? state, Duration? duration}) {
|
||||||
if (height == null && state == null)
|
if (height == null && state == null) {
|
||||||
throw ("Miniplayer: One of the two parameters, height or status, is required.");
|
throw ("Miniplayer: One of the two parameters, height or status, is required.");
|
||||||
|
}
|
||||||
|
|
||||||
if (height != null && state != null)
|
if (height != null && state != null) {
|
||||||
throw ("Miniplayer: Only one of the two parameters, height or status, can be specified.");
|
throw ("Miniplayer: Only one of the two parameters, height or status, can be specified.");
|
||||||
|
}
|
||||||
|
|
||||||
ControllerData? valBefore = value;
|
ControllerData? valBefore = value;
|
||||||
|
|
||||||
if (state != null)
|
if (state != null) {
|
||||||
value = ControllerData(state.heightCode, duration);
|
value = ControllerData(state.heightCode, duration);
|
||||||
else {
|
} else {
|
||||||
if (height! < 0) return;
|
if (height! < 0) return;
|
||||||
|
|
||||||
value = ControllerData(height.round(), duration);
|
value = ControllerData(height.round(), duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valBefore == value) notifyListeners();
|
if (valBefore == value) {
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue