200 lines
6.9 KiB
Dart
200 lines
6.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:miniplayer/miniplayer.dart';
|
|
import 'package:example/main.dart';
|
|
|
|
import '../utils.dart';
|
|
|
|
final ValueNotifier<double> playerExpandProgress =
|
|
ValueNotifier(playerMinHeight);
|
|
|
|
final MiniplayerController controller = MiniplayerController();
|
|
|
|
class DetailedPlayer extends StatelessWidget {
|
|
final AudioObject audioObject;
|
|
|
|
const DetailedPlayer({Key? key, required this.audioObject}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Miniplayer(
|
|
valueNotifier: playerExpandProgress,
|
|
minHeight: playerMinHeight,
|
|
maxHeight: playerMaxHeight,
|
|
controller: controller,
|
|
elevation: 4,
|
|
onDismissed: () => currentlyPlaying.value = null,
|
|
curve: Curves.easeOut,
|
|
builder: (height, percentage) {
|
|
final bool miniplayer = percentage < miniplayerPercentageDeclaration;
|
|
final double width = MediaQuery.of(context).size.width;
|
|
final maxImgSize = width * 0.4;
|
|
|
|
final img = Image.network(audioObject.img);
|
|
final text = Text(audioObject.title);
|
|
const buttonPlay = IconButton(
|
|
icon: Icon(Icons.pause),
|
|
onPressed: onTap,
|
|
);
|
|
final progressIndicator = LinearProgressIndicator(value: 0.3);
|
|
|
|
//Declare additional widgets (eg. SkipButton) and variables
|
|
if (!miniplayer) {
|
|
var percentageExpandedPlayer = percentageFromValueInRange(
|
|
min: playerMaxHeight * miniplayerPercentageDeclaration +
|
|
playerMinHeight,
|
|
max: playerMaxHeight,
|
|
value: height);
|
|
if (percentageExpandedPlayer < 0) percentageExpandedPlayer = 0;
|
|
final paddingVertical = valueFromPercentageInRange(
|
|
min: 0, max: 10, percentage: percentageExpandedPlayer);
|
|
final double heightWithoutPadding = height - paddingVertical * 2;
|
|
final double imageSize = heightWithoutPadding > maxImgSize
|
|
? maxImgSize
|
|
: heightWithoutPadding;
|
|
final paddingLeft = valueFromPercentageInRange(
|
|
min: 0,
|
|
max: width - imageSize,
|
|
percentage: percentageExpandedPlayer,
|
|
) /
|
|
2;
|
|
|
|
const buttonSkipForward = IconButton(
|
|
icon: Icon(Icons.forward_30),
|
|
iconSize: 33,
|
|
onPressed: onTap,
|
|
);
|
|
const buttonSkipBackwards = IconButton(
|
|
icon: Icon(Icons.replay_10),
|
|
iconSize: 33,
|
|
onPressed: onTap,
|
|
);
|
|
const buttonPlayExpanded = IconButton(
|
|
icon: Icon(Icons.pause_circle_filled),
|
|
iconSize: 50,
|
|
onPressed: onTap,
|
|
);
|
|
|
|
return Column(
|
|
children: [
|
|
Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: Padding(
|
|
padding: EdgeInsets.only(
|
|
left: paddingLeft,
|
|
top: paddingVertical,
|
|
bottom: paddingVertical),
|
|
child: SizedBox(
|
|
height: imageSize,
|
|
child: img,
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 33),
|
|
child: Opacity(
|
|
opacity: percentageExpandedPlayer,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
Flexible(child: text),
|
|
Flexible(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
buttonSkipBackwards,
|
|
buttonPlayExpanded,
|
|
buttonSkipForward
|
|
],
|
|
),
|
|
),
|
|
Flexible(child: progressIndicator),
|
|
Container(),
|
|
Container(),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
//Miniplayer
|
|
final percentageMiniplayer = percentageFromValueInRange(
|
|
min: playerMinHeight,
|
|
max: playerMaxHeight * miniplayerPercentageDeclaration +
|
|
playerMinHeight,
|
|
value: height);
|
|
|
|
final elementOpacity = 1 - 1 * percentageMiniplayer;
|
|
final progressIndicatorHeight = 4 - 4 * percentageMiniplayer;
|
|
|
|
return Column(
|
|
children: [
|
|
Expanded(
|
|
child: Row(
|
|
children: [
|
|
ConstrainedBox(
|
|
constraints: BoxConstraints(maxHeight: maxImgSize),
|
|
child: img,
|
|
),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 10),
|
|
child: Opacity(
|
|
opacity: elementOpacity,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(audioObject.title,
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.bodyText2!
|
|
.copyWith(fontSize: 16)),
|
|
Text(
|
|
audioObject.subtitle,
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.bodyText2!
|
|
.copyWith(
|
|
color: Colors.black.withOpacity(0.55)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: Icon(Icons.fullscreen),
|
|
onPressed: () {
|
|
controller.animateToHeight(state: PanelState.MAX);
|
|
}),
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: 3),
|
|
child: Opacity(
|
|
opacity: elementOpacity,
|
|
child: buttonPlay,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: progressIndicatorHeight,
|
|
child: Opacity(
|
|
opacity: elementOpacity,
|
|
child: progressIndicator,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
void onTap() {}
|