Skip to content

Commit

Permalink
fix: Seekbar duration text issue
Browse files Browse the repository at this point in the history
Remove three dot menu

Signed-off-by: Ashwin Ramakrishnan <[email protected]>
  • Loading branch information
ashwinkey04 committed Mar 4, 2021
1 parent 0e025cc commit 67eef45
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 124 deletions.
17 changes: 4 additions & 13 deletions lib/provider/player_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,19 @@ import 'package:flutter/material.dart';

enum PlayerState { stopped, playing, paused }

var audioManagerInstance = AudioManager.instance;

bool isPlaying = audioManagerInstance.isPlaying;
double slider = 0.0;

class PlayerProvider extends ChangeNotifier {
Duration duration;
Duration position;

PlayerState playerState = PlayerState.stopped;
PlayerState playerState;
double slider = 0.0;
var audioManagerInstance = AudioManager.instance;

get isPlaying => playerState == PlayerState.playing;

get isPaused => playerState == PlayerState.paused;

get durationText =>
duration != null ? duration.toString().split('.').first : '';

get positionText =>
position != null ? position.toString().split('.').first : '';

void setUpAudio() {
playerState = PlayerState.stopped;
audioManagerInstance.onEvents((events, args) {
switch (events) {
case AudioManagerEvents.start:
Expand Down
56 changes: 18 additions & 38 deletions lib/provider/song_widget.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:provider/provider.dart';
import 'package:raag/model/music_model.dart';
import 'package:raag/provider/player_provider.dart';
import 'package:raag/view/playback_controls.dart';
Expand Down Expand Up @@ -32,6 +32,7 @@ class _SongWidgetState extends State<SongWidget> with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
final provider = Provider.of<PlayerProvider>(context);

return Stack(
children: [
Expand All @@ -54,41 +55,12 @@ class _SongWidgetState extends State<SongWidget> with TickerProviderStateMixin {
color: Colors.transparent,
child: ListTile(
contentPadding: EdgeInsets.zero,
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
icon: Icon(
Icons.more_vert,
size: 20.0,
color: Theme.of(context).accentColor,
),
onPressed: () {
Fluttertoast.showToast(
msg: 'Feature yet to be released');
showMenu(
context: context,
position: RelativeRect.fromLTRB(100, 100, 0,
100), //TODO Should not be constant
items: [
PopupMenuItem<String>(
child: const Text('Like'),
value: 'Doge'),
PopupMenuItem<String>(
child: const Text('Add to Playlist'),
value: 'Lion'),
PopupMenuItem<String>(
child: const Text('Song info'),
value: 'Lion'),
]);
},
)
],
),
title: InkWell(
onTap: () {
if(audioManagerInstance.isPlaying) audioManagerInstance.toPause();
audioManagerInstance
if (provider.audioManagerInstance.isPlaying)
provider.audioManagerInstance.toPause();
provider.playerState = PlayerState.playing;
provider.audioManagerInstance
.start("file://${song.filePath}", song.title,
desc: song.displayName,
auto: true,
Expand All @@ -106,16 +78,20 @@ class _SongWidgetState extends State<SongWidget> with TickerProviderStateMixin {
),
SizedBox(width: screenWidth * 0.03,),
Container(
width: MediaQuery.of(context).size.width * 0.6,
width: MediaQuery
.of(context)
.size
.width * 0.7,
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(song.title,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
style: Theme
.of(context)
.textTheme
.headline3),
Text(song.artist,
Expand Down Expand Up @@ -143,7 +119,11 @@ class _SongWidgetState extends State<SongWidget> with TickerProviderStateMixin {
height: 0,
);
}),
PlayBackControls()
PlayBackControls(),
SizedBox(height: MediaQuery
.of(context)
.size
.height * 0.2,)
],
);
}
Expand Down
48 changes: 31 additions & 17 deletions lib/view/playback_controls.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:raag/provider/audio_helper.dart';
import 'package:raag/provider/player_provider.dart';
import 'package:raag/widgets/seekbar.dart';
Expand All @@ -11,11 +12,19 @@ class PlayBackControls extends StatefulWidget {
class _PlayBackControlsState extends State<PlayBackControls> {
@override
Widget build(BuildContext context) {
var glowShadow = BoxShadow(
color: Theme.of(context).accentColor.withOpacity(0.3),
spreadRadius: 3,
blurRadius: 9,
offset: Offset(0, 0), // changes position of shadow
);
final provider = Provider.of<PlayerProvider>(context);
return Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
decoration: BoxDecoration(
boxShadow: [glowShadow],
color: Theme.of(context).backgroundColor,
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
Expand Down Expand Up @@ -57,7 +66,7 @@ class _PlayBackControlsState extends State<PlayBackControls> {
),
elevation: 0,
onPressed: () {
audioManagerInstance.previous();
provider.audioManagerInstance.previous();
}),
),
),
Expand Down Expand Up @@ -85,10 +94,15 @@ class _PlayBackControlsState extends State<PlayBackControls> {
),
elevation: 0,
onPressed: () {
audioManagerInstance.isPlaying
? playFABController.reverse()
: playFABController.forward();
audioManagerInstance.playOrPause();
if (provider.audioManagerInstance.isPlaying) {
playFABController.reverse();
provider.playerState = PlayerState.paused;
}
else {
playFABController.forward();
provider.playerState = PlayerState.playing;
}
provider.audioManagerInstance.playOrPause();
}),
),
),
Expand All @@ -115,7 +129,7 @@ class _PlayBackControlsState extends State<PlayBackControls> {
),
elevation: 0,
onPressed: () {
audioManagerInstance.next();
provider.audioManagerInstance.next();
}),
),
),
Expand All @@ -134,17 +148,17 @@ class _PlayBackControlsState extends State<PlayBackControls> {
),
child: new Center(
child: RawMaterialButton(
shape: CircleBorder(),
onPressed: () {
audioManagerInstance.stop();
playFABController.reverse();
},
child: Icon(
Icons.stop,
color: Theme.of(context).accentColor,
),
elevation: 4,
)),
shape: CircleBorder(),
onPressed: () {
provider.audioManagerInstance.stop();
playFABController.reverse();
},
child: Icon(
Icons.stop,
color: Theme.of(context).accentColor,
),
elevation: 4,
)),
),
],
),
Expand Down
26 changes: 16 additions & 10 deletions lib/widgets/seekbar.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:raag/provider/audio_helper.dart';
import 'package:raag/provider/player_provider.dart';

Expand All @@ -10,10 +11,11 @@ class SeekBar extends StatefulWidget {
class _SeekBarState extends State<SeekBar> {
@override
Widget build(BuildContext context) {
final provider = Provider.of<PlayerProvider>(context);
return Row(
children: <Widget>[
Text(
formatDuration(audioManagerInstance.position),
formatDuration(provider.audioManagerInstance.position),
style: Theme.of(context).textTheme.subtitle2,
),
Expanded(
Expand All @@ -35,28 +37,32 @@ class _SeekBarState extends State<SeekBar> {
inactiveTrackColor: Theme.of(context).dividerColor,
),
child: Slider(
value: slider ?? 0,
value: provider.slider ?? 0,
onChanged: (value) {
setState(() {
slider = value;
provider.slider = value;
});
},
onChangeEnd: (value) {
if (audioManagerInstance.duration != null) {
if (provider.audioManagerInstance.duration != null) {
Duration msec = Duration(
milliseconds:
(audioManagerInstance.duration.inMilliseconds *
value)
.round());
audioManagerInstance.seekTo(msec);
(provider.audioManagerInstance.duration
.inMilliseconds *
value)
.round());
provider.audioManagerInstance.seekTo(msec);
}
},
)),
),
),
Text(
formatDuration(audioManagerInstance.duration),
style: Theme.of(context).textTheme.subtitle2,
formatDuration(provider.audioManagerInstance.duration),
style: Theme
.of(context)
.textTheme
.subtitle2,
),
],
);
Expand Down
Loading

0 comments on commit 67eef45

Please sign in to comment.