Organize package

This commit is contained in:
David 2020-09-26 15:12:50 +02:00
parent 6b478a9406
commit d61efc61cf
2 changed files with 19 additions and 17 deletions

View File

@ -3,6 +3,7 @@ library miniplayer;
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:miniplayer/src/utils.dart';
typedef Widget MiniplayerBuilder(double height, double percentage); typedef Widget MiniplayerBuilder(double height, double percentage);
@ -108,7 +109,7 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
GestureDetector( GestureDetector(
onTap: () => _animateToHeight(widget.minHeight), onTap: () => _animateToHeight(widget.minHeight),
child: Opacity( child: Opacity(
opacity: _borderDouble( opacity: borderDouble(
minRange: 0, maxRange: 1, value: _percentage), minRange: 0, maxRange: 1, value: _percentage),
child: Container(color: widget.backgroundColor), child: Container(color: widget.backgroundColor),
), ),
@ -124,7 +125,7 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
if (value == 0) return child; if (value == 0) return child;
return Opacity( return Opacity(
opacity: _borderDouble( opacity: borderDouble(
minRange: 0, maxRange: 1, value: 1 - value * 0.8), minRange: 0, maxRange: 1, value: 1 - value * 0.8),
child: Transform.translate( child: Transform.translate(
offset: Offset(0.0, widget.minHeight * value * 0.5), offset: Offset(0.0, widget.minHeight * value * 0.5),
@ -178,7 +179,7 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
///Determine to which SnapPosition the widget should snap ///Determine to which SnapPosition the widget should snap
SnapPosition snap = SnapPosition.MIN; SnapPosition snap = SnapPosition.MIN;
final _percentageMax = _percentageFromValueInRange( final _percentageMax = percentageFromValueInRange(
min: widget.minHeight, min: widget.minHeight,
max: widget.maxHeight, max: widget.maxHeight,
value: _dragHeight); value: _dragHeight);
@ -197,7 +198,7 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
///DismissedPercentage > 0.2 -> dismiss ///DismissedPercentage > 0.2 -> dismiss
if (widget.onDismiss != null && if (widget.onDismiss != null &&
_percentageFromValueInRange( percentageFromValueInRange(
min: widget.minHeight, min: widget.minHeight,
max: 0, max: 0,
value: _dragHeight) > value: _dragHeight) >
@ -238,10 +239,10 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
///Drag below minHeight ///Drag below minHeight
else if (widget.onDismiss != null) { else if (widget.onDismiss != null) {
var percentageDown = _borderDouble( var percentageDown = borderDouble(
minRange: 0, minRange: 0,
maxRange: 1, maxRange: 1,
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)
@ -293,14 +294,3 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
_animationController.forward(from: 0); _animationController.forward(from: 0);
} }
} }
///Calculates the percentage of a value within a given range of values
double _percentageFromValueInRange({final double min, max, value}) {
return (value - min) / (max - min);
}
double _borderDouble({double minRange, double maxRange, double value}) {
if (value > maxRange) return maxRange;
if (value < minRange) return minRange;
return value;
}

12
lib/src/utils.dart Normal file
View File

@ -0,0 +1,12 @@
enum SnapPosition { MAX, MIN, DISMISS }
///Calculates the percentage of a value within a given range of values
double percentageFromValueInRange({final double min, max, value}) {
return (value - min) / (max - min);
}
double borderDouble({double minRange, double maxRange, double value}) {
if (value > maxRange) return maxRange;
if (value < minRange) return minRange;
return value;
}