Use curly brackets

This commit is contained in:
david.peters 2021-11-10 23:01:47 +01:00
parent 93e82a73f6
commit 8358e625a5
1 changed files with 62 additions and 34 deletions

View File

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