Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Ambient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Daniel Furaev
Ambient
Commits
7ce1b7c7
Commit
7ce1b7c7
authored
2 years ago
by
Erik Hinkelmanns
Browse files
Options
Downloads
Patches
Plain Diff
outsourced play/pause button in controlButtons widget
parent
9c5177cf
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/homepage.dart
+39
-27
39 additions, 27 deletions
lib/homepage.dart
lib/main.dart
+14
-30
14 additions, 30 deletions
lib/main.dart
lib/widgets/musicPlayerState.dart
+23
-1
23 additions, 1 deletion
lib/widgets/musicPlayerState.dart
with
76 additions
and
58 deletions
lib/homepage.dart
+
39
−
27
View file @
7ce1b7c7
...
...
@@ -130,24 +130,7 @@ class HomePage extends StatelessWidget {
child:
Icon
(
Icons
.
skip_previous_outlined
)),
onPressed:
skipPrevious
,
),
playerState
.
isPaused
?
IconButton
(
icon:
const
Icon
(
Icons
.
play_arrow_outlined
),
iconSize:
50
,
onPressed:
(){
var
state
=
MusicPlayerState
.
of
(
context
);
SpotifySdk
.
resume
()
.
then
((
value
)
=
>
state
.
rebuildStream
.
sink
.
add
(
Null
));
}
)
:
IconButton
(
icon:
const
Icon
(
Icons
.
pause_outlined
),
iconSize:
50
,
color:
primaryColor
,
onPressed:
(){
var
state
=
MusicPlayerState
.
of
(
context
);
SpotifySdk
.
pause
()
.
then
((
value
)
=
>
state
.
rebuildStream
.
sink
.
add
(
Null
));
}
),
ControlButtons
(),
IconButton
(
iconSize:
50.0
,
icon:
const
Padding
(
...
...
@@ -165,15 +148,8 @@ class HomePage extends StatelessWidget {
Future
getPlayerState
()
async
{
try
{
return
await
SpotifySdk
.
getPlayerState
();
}
on
PlatformException
catch
(
e
)
{
setStatus
(
e
.
code
,
message:
e
.
message
);
}
on
MissingPluginException
{
setStatus
(
'not implemented'
);
}
}
Future
<
void
>
queue
(
String
songId
)
async
{
try
{
...
...
@@ -265,6 +241,42 @@ class HomePage extends StatelessWidget {
ScaffoldMessenger
.
of
(
context
)
.
showSnackBar
(
snackBar
);
}
}
class
ControlButtons
extends
StatelessWidget
{
const
ControlButtons
({
Key
?
key
,
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
if
(
MusicPlayerState
.
of
(
context
)
.
playerState
==
null
){
return
const
Text
(
"PlayState is Null"
);
}
else
{
if
(
MusicPlayerState
.
of
(
context
)
.
playerState
!.
isPaused
)
{
return
IconButton
(
icon:
const
Icon
(
Icons
.
play_arrow_outlined
),
iconSize:
50
,
onPressed:
()
{
var
state
=
MusicPlayerState
.
of
(
context
);
SpotifySdk
.
resume
()
.
then
((
value
)
=
>
state
.
updatePlayerState
());
});
}
else
{
return
IconButton
(
icon:
const
Icon
(
Icons
.
pause_outlined
),
iconSize:
50
,
color:
primaryColor
,
onPressed:
()
{
var
state
=
MusicPlayerState
.
of
(
context
);
SpotifySdk
.
pause
()
.
then
((
value
)
=
>
state
.
updatePlayerState
());
},
);
}
}
}
}
Color
darken
(
Color
color
,
[
double
amount
=
.
1
])
{
...
...
This diff is collapsed.
Click to expand it.
lib/main.dart
+
14
−
30
View file @
7ce1b7c7
...
...
@@ -3,6 +3,7 @@ import 'package:ambient/widgets/MusicPlayerState.dart';
import
'package:ambient/widgets/navbars.dart'
;
import
'package:firebase_core/firebase_core.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_dotenv/flutter_dotenv.dart'
;
import
'package:spotify_sdk/models/player_state.dart'
;
import
'package:spotify_sdk/spotify_sdk.dart'
;
...
...
@@ -138,31 +139,14 @@ class MusicBar extends StatelessWidget {
child:
Row
(
children:
[
MusicPlayerState
.
of
(
context
)
.
albumImage
,
playerState
.
isPaused
?
IconButton
(
icon:
Icon
(
Icons
.
play_arrow_outlined
),
iconSize:
50
,
onPressed:
(){
var
state
=
MusicPlayerState
.
of
(
context
);
SpotifySdk
.
resume
()
.
then
((
value
)
=
>
state
.
rebuildStream
.
sink
.
add
(
Null
));
}
)
:
IconButton
(
icon:
Icon
(
Icons
.
pause_outlined
),
iconSize:
50
,
color:
primaryColor
,
onPressed:
()
{
var
state
=
MusicPlayerState
.
of
(
context
);
SpotifySdk
.
pause
()
.
then
((
value
)
=
>
state
.
rebuildStream
.
sink
.
add
(
Null
));
},
),
ControlButtons
(),
],
),
);
});
}
else
{
return
Text
(
"not Connected"
);
return
const
Text
(
"not Connected"
);
}
}
}
This diff is collapsed.
Click to expand it.
lib/widgets/musicPlayerState.dart
+
23
−
1
View file @
7ce1b7c7
...
...
@@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
import
'package:flutter/widgets.dart'
;
import
'package:flutter_dotenv/flutter_dotenv.dart'
;
import
'package:spotify_sdk/models/image_uri.dart'
;
import
'package:spotify_sdk/models/player_state.dart'
;
import
'package:spotify_sdk/spotify_sdk.dart'
;
...
...
@@ -12,10 +13,13 @@ class MusicPlayerState extends InheritedWidget {
bool
loading
=
false
;
bool
connected
=
false
;
StreamController
<
void
>
rebuildStream
=
new
StreamController
.
broadcast
();
StreamController
<
void
>
rebuildStream
=
StreamController
.
broadcast
();
StreamController
<
void
>
playStatedStream
=
StreamController
.
broadcast
();
late
PlayerState
?
playerState
;
late
ImageUri
?
currentTrackImageUri
;
late
Image
albumImage
;
static
MusicPlayerState
?
maybeOf
(
BuildContext
context
)
=
>
context
.
dependOnInheritedWidgetOfExactType
<
MusicPlayerState
>();
...
...
@@ -30,6 +34,10 @@ class MusicPlayerState extends InheritedWidget {
rebuildStream
.
sink
.
add
(
Null
);
}
void
updatePlayerState
()
async
{
playerState
=
await
getPlayerState
();
rebuildStream
.
sink
.
add
(
Null
);
}
Future
<
void
>
disconnect
()
async
{
try
{
...
...
@@ -56,6 +64,9 @@ class MusicPlayerState extends InheritedWidget {
setStatus
(
result
?
'connect to spotify successful'
:
'connect to spotify failed'
);
if
(
result
){
playerState
=
await
getPlayerState
();
}
setLoading
(
false
);
isConnected
=
result
;
}
on
PlatformException
catch
(
e
)
{
...
...
@@ -96,11 +107,22 @@ class MusicPlayerState extends InheritedWidget {
});
}
void
setStatus
(
String
code
,
{
String
?
message
})
{
var
text
=
message
??
''
;
print
(
text
);
}
Future
<
PlayerState
?
>
getPlayerState
()
async
{
try
{
return
await
SpotifySdk
.
getPlayerState
();
}
on
PlatformException
catch
(
e
)
{
setStatus
(
e
.
code
,
message:
e
.
message
);
}
on
MissingPluginException
{
setStatus
(
'not implemented'
);
}
}
@override
bool
updateShouldNotify
(
covariant
MusicPlayerState
oldWidget
)
{
return
loading
!=
oldWidget
.
loading
&&
connected
!=
oldWidget
.
connected
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment