Compare commits

...

5 Commits

Author SHA1 Message Date
poka bd9e0bc4e8 Fix backgroundColor using 2022-04-29 13:06:31 +02:00
david.peters 735963a9bc Remove unnecessary code line (#22) 2021-11-10 23:02:41 +01:00
david.peters 8358e625a5 Use curly brackets 2021-11-10 23:01:47 +01:00
david.peters 93e82a73f6 Use path dependency in example project 2021-11-10 23:00:56 +01:00
David Peters 2ce48a3f46 Bump version to 1.0.1 2021-09-29 17:22:40 +02:00
5 changed files with 95 additions and 63 deletions

View File

@ -1,3 +1,8 @@
## 1.0.1
* Added dark theme support [#13](https://github.com/peterscodee/miniplayer/issues/13)
* Removed overflow errors in the example app [#14](https://github.com/peterscodee/miniplayer/issues/14)
## 1.0.0+2
* Fixed a bug introduced with the null safety release

View File

@ -7,49 +7,49 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.2"
version: "2.8.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
version: "1.3.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.13"
version: "1.15.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
@ -66,28 +66,28 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.8"
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
version: "1.7.0"
miniplayer:
dependency: "direct main"
description:
name: miniplayer
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.0"
path: ".."
relative: true
source: path
version: "1.0.1"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
sky_engine:
dependency: transitive
description: flutter
@ -99,56 +99,55 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.5"
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.17"
version: "0.4.2"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
version: "2.1.0"
sdks:
dart: ">=2.9.0-14.0.dev <3.0.0"
flutter: ">=1.0.0 <2.0.0"
dart: ">=2.12.0 <3.0.0"

View File

@ -24,7 +24,9 @@ dependencies:
flutter:
sdk: flutter
miniplayer: ^1.0.0
miniplayer:
path:
../
dev_dependencies:
flutter_test:

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 {
@ -180,8 +191,6 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
valueListenable: dragDownPercentage,
builder:
(BuildContext context, double value, Widget? child) {
if (value == 0) return child!;
return Opacity(
opacity: borderDouble(
minRange: 0.0,
@ -204,7 +213,7 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
blurRadius: widget.elevation,
offset: Offset(0.0, 4))
],
color: Theme.of(context).canvasColor,
color: widget.backgroundColor, //kopa
),
),
),
@ -216,7 +225,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 +240,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 +258,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 +306,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 +317,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 +356,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 +430,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();
}
}
}

View File

@ -1,6 +1,6 @@
name: miniplayer
description: A lightweight flutter package to simplify the creation of a miniplayer.
version: 1.0.0+2
version: 1.0.1
homepage: https://www.peterscode.dev
repository: https://github.com/peterscodee/miniplayer