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
9ccf54cf
Commit
9ccf54cf
authored
2 years ago
by
Erik Hinkelmanns
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/main' into music_player
parents
ec0da04a
92ecf463
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
lib/moodpage.dart
+18
-17
18 additions, 17 deletions
lib/moodpage.dart
lib/searchpage.dart
+22
-9
22 additions, 9 deletions
lib/searchpage.dart
lib/services/spotify.dart
+48
-0
48 additions, 0 deletions
lib/services/spotify.dart
lib/widgets/navbars.dart
+51
-11
51 additions, 11 deletions
lib/widgets/navbars.dart
with
139 additions
and
37 deletions
lib/moodpage.dart
+
18
−
17
View file @
9ccf54cf
...
@@ -53,6 +53,7 @@ class MoodPage extends State<StateMoodPage> {
...
@@ -53,6 +53,7 @@ class MoodPage extends State<StateMoodPage> {
Moods
?
currentMood
=
selectedMoodAsEnum
;
Moods
?
currentMood
=
selectedMoodAsEnum
;
String
imagePath
=
""
;
String
imagePath
=
""
;
//besorgt ein image file aus der galarie
_getFromGallery
()
async
{
_getFromGallery
()
async
{
try
{
try
{
XFile
?
pickedFile
=
await
_picker
.
pickImage
(
XFile
?
pickedFile
=
await
_picker
.
pickImage
(
...
@@ -71,14 +72,14 @@ class MoodPage extends State<StateMoodPage> {
...
@@ -71,14 +72,14 @@ class MoodPage extends State<StateMoodPage> {
print
(
e
);
print
(
e
);
}
}
}
}
//sendet den befehl music zum passenden genre rauszusuchen
_changeMusic
()
async
{
_changeMusic
()
async
{
//code zum musik ändern
//code zum musik ändern
String
hexcode
=
selectedMood
.
red
.
toRadixString
(
16
)
+
selectedMood
.
green
.
toRadixString
(
16
)
+
selectedMood
.
blue
.
toRadixString
(
16
);
String
hexcode
=
selectedMood
.
red
.
toRadixString
(
16
)
+
selectedMood
.
green
.
toRadixString
(
16
)
+
selectedMood
.
blue
.
toRadixString
(
16
);
String
genre
=
await
changeFirebase
()
.
getGenreByHex
(
hexcode
);
String
genre
=
await
changeFirebase
()
.
getGenreByHex
(
hexcode
);
print
(
"genre = "
+
genre
);
print
(
"genre = "
+
genre
);
}
}
//vergleicht zwei farben auf ähnlichkeit
_getColorDistance
(
Color
c1
,
Color
c2
)
{
_getColorDistance
(
Color
c1
,
Color
c2
)
{
LabColor
labC1
=
LabColor
.
fromColor
(
c1
);
LabColor
labC1
=
LabColor
.
fromColor
(
c1
);
LabColor
labC2
=
LabColor
.
fromColor
(
c2
);
LabColor
labC2
=
LabColor
.
fromColor
(
c2
);
...
@@ -127,22 +128,21 @@ class MoodPage extends State<StateMoodPage> {
...
@@ -127,22 +128,21 @@ class MoodPage extends State<StateMoodPage> {
}
}
_updateColorPalete
(
Color
col
){
_updateColorPalete
(
Color
col
){
if
(
!
usesPicture
){
if
(
!
usesPicture
){
col
=
Color
.
fromARGB
(
col
.
alpha
-
100
,
col
.
red
,
col
.
green
,
col
.
blue
);
if
(
col
.
value
!=
Color
.
fromARGB
(
255
,
0
,
0
,
0
)
.
value
){
//col = darken(col, 0.05);
col
=
ligten
(
col
,
0.2
);
}
primaryColor
=
col
;
primaryColor
=
col
;
backGroundColor
=
Color
.
fromARGB
(
col
.
alpha
-
140
,
col
.
red
,
col
.
green
,
col
.
blue
);
}
else
{
backGroundColor
=
Color
.
fromARGB
(
col
.
alpha
-
240
,
col
.
red
,
col
.
green
,
col
.
blue
);
}
}
backGroundColor
=
Color
.
fromARGB
(
col
.
alpha
-
230
,
col
.
red
,
col
.
green
,
col
.
blue
);
primaryColor
=
col
;
primaryColor
=
col
;
onPrimary
=
darken
(
col
,
0.
2
);
onPrimary
=
darken
(
col
,
0.
5
);
Color
shiftedColor
=
Color
.
fromARGB
(
col
.
alpha
-
100
,
col
.
red
,
col
.
green
,
col
.
blue
);
Color
shiftedColor
=
ligten
(
col
,
0.1
);
;
primaryContainer
=
shiftedColor
;
primaryContainer
=
shiftedColor
;
onPrimaryContainer
=
darken
(
shiftedColor
,
0.
2
);
onPrimaryContainer
=
darken
(
shiftedColor
,
0.
5
);
}
}
//returend die liste mit den moods
_getMoodList
(){
_getMoodList
(){
return
Column
(
children:
<
Widget
>[
return
Column
(
children:
<
Widget
>[
...
@@ -230,6 +230,7 @@ class MoodPage extends State<StateMoodPage> {
...
@@ -230,6 +230,7 @@ class MoodPage extends State<StateMoodPage> {
});
});
},
},
),
),
RadioListTile
<
Moods
>(
RadioListTile
<
Moods
>(
title:
const
Text
(
title:
const
Text
(
"Happy"
,
"Happy"
,
...
@@ -358,7 +359,7 @@ class MoodPage extends State<StateMoodPage> {
...
@@ -358,7 +359,7 @@ class MoodPage extends State<StateMoodPage> {
),
),
]);
]);
}
}
// setzt das bild(falls vorhanden) in einem container ein der sich and die bildschirmgröße anpasst
_getContainerTodisplay
()
{
_getContainerTodisplay
()
{
BoxDecoration
deco
=
new
BoxDecoration
();
BoxDecoration
deco
=
new
BoxDecoration
();
var
image
;
var
image
;
...
@@ -386,7 +387,7 @@ class MoodPage extends State<StateMoodPage> {
...
@@ -386,7 +387,7 @@ class MoodPage extends State<StateMoodPage> {
),
),
);
);
}
}
//generiert ein image aus dem imagefile
_getImageTodisplay
()
{
_getImageTodisplay
()
{
var
imageToShow
;
var
imageToShow
;
try
{
try
{
...
@@ -396,7 +397,7 @@ class MoodPage extends State<StateMoodPage> {
...
@@ -396,7 +397,7 @@ class MoodPage extends State<StateMoodPage> {
return
null
;
return
null
;
}
}
}
}
// generiert einen paletegenerator vom aktiellen image
Future
<
PaletteGenerator
>
_updatePaletteGenerator
()
async
{
Future
<
PaletteGenerator
>
_updatePaletteGenerator
()
async
{
if
(
imagePath
!=
""
)
{
if
(
imagePath
!=
""
)
{
paletteGenerator
=
await
PaletteGenerator
.
fromImageProvider
(
paletteGenerator
=
await
PaletteGenerator
.
fromImageProvider
(
...
@@ -405,8 +406,8 @@ class MoodPage extends State<StateMoodPage> {
...
@@ -405,8 +406,8 @@ class MoodPage extends State<StateMoodPage> {
}
}
return
paletteGenerator
;
return
paletteGenerator
;
}
}
//gibt dem widged den colorindicator zur momentan generierten Primärfarbe und die Moodliste mit dem aktuell auszuwählenden Mood zurück
_getCollorIndicator
()
{
_getCollorIndicator
AndMoodList
()
{
return
FutureBuilder
<
PaletteGenerator
>(
return
FutureBuilder
<
PaletteGenerator
>(
future:
_updatePaletteGenerator
(),
// async work
future:
_updatePaletteGenerator
(),
// async work
builder:
builder:
...
@@ -456,7 +457,7 @@ class MoodPage extends State<StateMoodPage> {
...
@@ -456,7 +457,7 @@ class MoodPage extends State<StateMoodPage> {
child:
Column
(
child:
Column
(
children:
<
Widget
>[
children:
<
Widget
>[
_getContainerTodisplay
(),
_getContainerTodisplay
(),
_getCollorIndicator
(),
_getCollorIndicator
AndMoodList
(),
//_getMoodList(),
//_getMoodList(),
],
],
),
),
...
...
This diff is collapsed.
Click to expand it.
lib/searchpage.dart
+
22
−
9
View file @
9ccf54cf
...
@@ -3,6 +3,9 @@ import 'package:flutter/material.dart';
...
@@ -3,6 +3,9 @@ import 'package:flutter/material.dart';
import
'dart:developer'
;
import
'dart:developer'
;
import
'package:ambient/services/spotify.dart'
;
import
'package:ambient/services/spotify.dart'
;
import
'package:ambient/homepage.dart'
;
import
'package:flutter/services.dart'
;
import
'package:spotify_sdk/spotify_sdk.dart'
;
class
StateSearcgPage
extends
StatefulWidget
{
class
StateSearcgPage
extends
StatefulWidget
{
const
StateSearcgPage
({
super
.
key
});
const
StateSearcgPage
({
super
.
key
});
...
@@ -14,6 +17,7 @@ class StateSearcgPage extends StatefulWidget {
...
@@ -14,6 +17,7 @@ class StateSearcgPage extends StatefulWidget {
class
SearchPage
extends
State
<
StateSearcgPage
>
{
class
SearchPage
extends
State
<
StateSearcgPage
>
{
final
controller
=
TextEditingController
();
final
controller
=
TextEditingController
();
Spotify
spotifyApi
=
Spotify
();
Spotify
spotifyApi
=
Spotify
();
HomePage
homePage
=
HomePage
();
List
<
Song
>
songs
=
List
.
empty
(
growable:
true
);
List
<
Song
>
songs
=
List
.
empty
(
growable:
true
);
@override
@override
...
@@ -45,8 +49,7 @@ class SearchPage extends State<StateSearcgPage> {
...
@@ -45,8 +49,7 @@ class SearchPage extends State<StateSearcgPage> {
itemCount:
songs
.
length
,
itemCount:
songs
.
length
,
itemBuilder:
((
context
,
index
)
{
itemBuilder:
((
context
,
index
)
{
Song
song
=
songs
[
index
];
Song
song
=
songs
[
index
];
return
GestureDetector
(
return
Card
(
child:
Padding
(
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
10
),
padding:
const
EdgeInsets
.
all
(
10
),
child:
Row
(
child:
Row
(
...
@@ -65,6 +68,9 @@ class SearchPage extends State<StateSearcgPage> {
...
@@ -65,6 +68,9 @@ class SearchPage extends State<StateSearcgPage> {
],
],
),
),
),
),
onTap:
()
{
play
(
song
.
id
);
},
);
);
})),
})),
)
)
...
@@ -73,14 +79,21 @@ class SearchPage extends State<StateSearcgPage> {
...
@@ -73,14 +79,21 @@ class SearchPage extends State<StateSearcgPage> {
}
}
updateList
(
String
searchedString
)
async
{
updateList
(
String
searchedString
)
async
{
if
(
searchedString
.
length
>
=
3
)
{
songs
=
List
.
empty
(
growable:
true
);
var
searchList
=
await
spotifyApi
.
search
(
searchedString
);
var
searchList
=
await
spotifyApi
.
search
(
searchedString
);
for
(
var
element
in
searchList
)
{
for
(
var
element
in
searchList
)
{
songs
.
add
(
element
);
songs
.
add
(
element
);
}
}
}
else
if
(
searchedString
.
isEmpty
)
{
}
songs
=
List
.
empty
(
growable:
true
);
Future
<
void
>
play
(
String
songId
)
async
{
try
{
await
SpotifySdk
.
play
(
spotifyUri:
'spotify:track:
$songId
'
);
}
on
PlatformException
catch
(
e
)
{
//setStatus(e.code, message: e.message);
}
on
MissingPluginException
{
//setStatus('not implemented');
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
lib/services/spotify.dart
+
48
−
0
View file @
9ccf54cf
...
@@ -2,7 +2,9 @@ import 'dart:convert';
...
@@ -2,7 +2,9 @@ import 'dart:convert';
import
'dart:developer'
;
import
'dart:developer'
;
import
'dart:io'
;
import
'dart:io'
;
import
'package:flutter/services.dart'
;
import
'package:http/http.dart'
as
http
;
import
'package:http/http.dart'
as
http
;
import
'package:spotify_sdk/spotify_sdk.dart'
;
class
Spotify
{
class
Spotify
{
final
clientId
=
'60cf1944b15d4f9fb223ba32ce6336d1'
;
final
clientId
=
'60cf1944b15d4f9fb223ba32ce6336d1'
;
...
@@ -61,6 +63,42 @@ class Spotify {
...
@@ -61,6 +63,42 @@ class Spotify {
}
}
}
}
playGenre
(
genre
)
async
{
try
{
final
response
=
await
http
.
get
(
Uri
.
parse
(
'https://api.spotify.com/v1/search?q=genre=
$genre
'
),
headers:
{
// 'Authorization': 'Bearer $authToken',
'Authorization'
:
'Bearer BQBx44KHYThkfXDRdxk9MNUaepkW_29jFARFKqOcO11ukDjdzuHY4dzNg2vl_8QPZ2wHX9NzTYaYFbwEjt5a83MD9oHoBTrbgjwvzGRQkL8L6LLz571amR-YhhxTsH9pG8ClYDZv2zgUgKgqXH6W64YCfyYSTiqYWnjKuUGSTyVUnz-BEQTTqbjJqemR4H-thfA9oWQDp07Ud2hOtI8Q'
},
);
final
responseJson
=
json
.
decode
(
response
.
body
);
final
items
=
responseJson
[
'tracks'
][
'items'
]
as
List
;
List
songList
=
items
.
map
((
item
)
=
>
Song
.
fromJson
(
item
))
.
toList
();
var
playSong
=
songList
.
first
();
play
(
playSong
[
'id'
]);
// T
}
catch
(
e
)
{
log
(
e
.
toString
());
}
}
getUser
()
async
{
try
{
var
response
=
await
http
.
get
(
Uri
.
parse
(
"https://api.spotify.com/v1/me"
),
headers:
{
HttpHeaders
.
authorizationHeader
:
authToken
},
);
return
response
;
}
catch
(
e
)
{
log
(
e
.
toString
());
}
}
getUserAlbums
()
async
{
getUserAlbums
()
async
{
try
{
try
{
var
response
=
await
http
.
get
(
var
response
=
await
http
.
get
(
...
@@ -193,6 +231,16 @@ class Spotify {
...
@@ -193,6 +231,16 @@ class Spotify {
log
(
e
.
toString
());
log
(
e
.
toString
());
}
}
}
}
Future
<
void
>
play
(
String
songId
)
async
{
try
{
await
SpotifySdk
.
play
(
spotifyUri:
'spotify:track:
$songId
'
);
}
on
PlatformException
catch
(
e
)
{
//setStatus(e.code, message: e.message);
}
on
MissingPluginException
{
//setStatus('not implemented');
}
}
}
}
class
Song
{
class
Song
{
...
...
This diff is collapsed.
Click to expand it.
lib/widgets/navbars.dart
+
51
−
11
View file @
9ccf54cf
// ignore_for_file: prefer_const_constructors
import
'package:ambient/services/spotify.dart'
;
import
'package:firebase_auth/firebase_auth.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'../loginRegister/login.dart'
;
import
'../main.dart'
;
import
'../main.dart'
;
//Todo Daniel Sidebar
//Todo Daniel Sidebar
class
SettingsDrawer
extends
StatelessWidget
{
class
SettingsDrawer
extends
StatelessWidget
{
const
SettingsDrawer
({
const
SettingsDrawer
({
...
@@ -10,12 +14,51 @@ class SettingsDrawer extends StatelessWidget {
...
@@ -10,12 +14,51 @@ class SettingsDrawer extends StatelessWidget {
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
Spotify
spotify
=
Spotify
();
var
user
=
spotify
.
getUser
();
return
Drawer
(
return
Drawer
(
backgroundColor:
onPrimary
,
child:
ListView
(
width:
200
,
padding:
EdgeInsets
.
zero
,
child:
Center
(
children:
[
child:
Text
(
"Moin"
,
UserAccountsDrawerHeader
(
style:
TextStyle
(
fontSize:
30
,
color:
onPrimaryContainer
)),
accountName:
user
[
'display_name'
],
accountEmail:
user
[
'email'
],
currentAccountPicture:
CircleAvatar
(
child:
ClipOval
(
child:
Image
.
network
(
user
[
'images'
][
0
][
'url'
],
width:
90
,
height:
90
,
fit:
BoxFit
.
cover
,
)),
),
decoration:
BoxDecoration
(
color:
Colors
.
blue
,
image:
DecorationImage
(
image:
NetworkImage
(
'https://www.geeklawblog.com/wp-content/uploads/sites/528/2018/12/liprofile.png'
),
fit:
BoxFit
.
cover
,
)),
),
ListTile
(
leading:
Icon
(
Icons
.
favorite
),
title:
Text
(
'Favoriten'
),
onTap:
()
{
//TODO: Site to Favorite
},
),
ListTile
(
leading:
Icon
(
Icons
.
exit_to_app
),
title:
Text
(
'Abmelden'
),
onTap:
()
{
FirebaseAuth
.
instance
.
signOut
()
.
then
((
value
)
{
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=
>
LoginPage
()));
});
},
)
],
),
),
);
);
}
}
...
@@ -25,9 +68,7 @@ class Topbar extends StatelessWidget implements PreferredSizeWidget {
...
@@ -25,9 +68,7 @@ class Topbar extends StatelessWidget implements PreferredSizeWidget {
final
Text
title
;
final
Text
title
;
final
double
height
=
50
;
final
double
height
=
50
;
const
Topbar
({
Key
?
key
,
this
.
title
=
const
Text
(
"Navbar"
)})
const
Topbar
({
Key
?
key
,
this
.
title
=
const
Text
(
"Navbar"
)})
:
super
(
key:
key
);
:
super
(
key:
key
);
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
...
@@ -37,8 +78,7 @@ class Topbar extends StatelessWidget implements PreferredSizeWidget {
...
@@ -37,8 +78,7 @@ class Topbar extends StatelessWidget implements PreferredSizeWidget {
title:
title
,
title:
title
,
actions:
[
actions:
[
Builder
(
Builder
(
builder:
(
BuildContext
context
)
=
>
builder:
(
BuildContext
context
)
=
>
IconButton
(
IconButton
(
icon:
const
Icon
(
Icons
.
settings_outlined
),
icon:
const
Icon
(
Icons
.
settings_outlined
),
onPressed:
()
=
>
Scaffold
.
of
(
context
)
.
openEndDrawer
(),
onPressed:
()
=
>
Scaffold
.
of
(
context
)
.
openEndDrawer
(),
))
))
...
...
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