API cleanup

This commit is contained in:
David 2020-11-21 11:32:25 +01:00
parent fa05702092
commit 2e4f701c81
1 changed files with 21 additions and 5 deletions

View File

@ -8,6 +8,9 @@ import 'package:miniplayer/src/utils.dart';
///Type definition for the builder function ///Type definition for the builder function
typedef Widget MiniplayerBuilder(double height, double percentage); typedef Widget MiniplayerBuilder(double height, double percentage);
///Type definition for onDismiss. Will be used in a future version.
typedef void DismissCallback(double percentage);
///Miniplayer class ///Miniplayer class
class Miniplayer extends StatefulWidget { class Miniplayer extends StatefulWidget {
///Required option to set the minimum and maximum height ///Required option to set the minimum and maximum height
@ -33,9 +36,14 @@ class Miniplayer extends StatefulWidget {
///This can be used to hide the BottomNavigationBar. ///This can be used to hide the BottomNavigationBar.
final ValueNotifier<double> valueNotifier; final ValueNotifier<double> valueNotifier;
///If onDismiss is set, the miniplayer can be dismissed ///Deprecated
@Deprecated(
"Migrate onDismiss to onDismissed as onDismiss will be used differently in a future version.")
final Function onDismiss; final Function onDismiss;
///If onDismissed is set, the miniplayer can be dismissed
final Function onDismissed;
//Allows you to manually control the miniplayer in code //Allows you to manually control the miniplayer in code
final MiniplayerController controller; final MiniplayerController controller;
@ -50,6 +58,7 @@ class Miniplayer extends StatefulWidget {
this.valueNotifier, this.valueNotifier,
this.duration = const Duration(milliseconds: 300), this.duration = const Duration(milliseconds: 300),
this.onDismiss, this.onDismiss,
this.onDismissed,
this.controller, this.controller,
}) : super(key: key); }) : super(key: key);
@ -61,7 +70,8 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
ValueNotifier<double> heightNotifier; ValueNotifier<double> heightNotifier;
ValueNotifier<double> dragDownPercentage = ValueNotifier(0); ValueNotifier<double> dragDownPercentage = ValueNotifier(0);
PanelState snap; ///Temporary variable as long as onDismiss is deprecated. Will be removed in a future version.
Function onDismissed;
///Current y position of drag gesture ///Current y position of drag gesture
double _dragHeight; double _dragHeight;
@ -108,6 +118,12 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
if (widget.controller != null) if (widget.controller != null)
widget.controller.addListener(controllerListener); widget.controller.addListener(controllerListener);
if (widget.onDismissed != null)
onDismissed = widget.onDismissed;
else
// ignore: deprecated_member_use_from_same_package
onDismissed = widget.onDismiss;
super.initState(); super.initState();
} }
@ -226,7 +242,7 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
else else
///DismissedPercentage > 0.2 -> dismiss ///DismissedPercentage > 0.2 -> dismiss
if (widget.onDismiss != null && if (onDismissed != null &&
percentageFromValueInRange( percentageFromValueInRange(
min: widget.minHeight, min: widget.minHeight,
max: 0, max: 0,
@ -267,7 +283,7 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
} }
///Drag below minHeight ///Drag below minHeight
else if (widget.onDismiss != null) { else if (onDismissed != null) {
var percentageDown = borderDouble( var percentageDown = borderDouble(
minRange: 0, minRange: 0,
maxRange: 1, maxRange: 1,
@ -278,7 +294,7 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
dragDownPercentage.value = percentageDown; dragDownPercentage.value = percentageDown;
if (percentageDown >= 1 && animation && !dismissed) { if (percentageDown >= 1 && animation && !dismissed) {
if (widget.onDismiss != null) widget.onDismiss(); if (onDismissed != null) onDismissed();
setState(() { setState(() {
dismissed = true; dismissed = true;
}); });