Skip to content
Snippets Groups Projects
Commit 69cd3823 authored by Erik Hinkelmanns's avatar Erik Hinkelmanns
Browse files

Merge remote-tracking branch 'origin/madlen' into mergeHELL

# Conflicts:
#	lib/main.dart
#	lib/registration.dart
parents c8cddf8a 0f7ba831
Branches
No related tags found
No related merge requests found
import 'package:flutter/material.dart';
class CustomSearchDelegate extends SearchDelegate {
import '../firebase.dart';
class CustomSearchDelegate extends SearchDelegate<String>{
String colorText;
CustomSearchDelegate(this.colorText);
late String searchGenre;
// Demo list to show querying
static List<String> searchTerms = [
"acoustic",
......@@ -131,6 +137,7 @@ class CustomSearchDelegate extends SearchDelegate {
"world-music"
];
// first overwrite to
// clear the search text
@override
......@@ -150,7 +157,7 @@ class CustomSearchDelegate extends SearchDelegate {
Widget? buildLeading(BuildContext context) {
return IconButton(
onPressed: () {
close(context, null);
close(context, '');
},
icon: Icon(Icons.arrow_back),
);
......@@ -192,8 +199,12 @@ class CustomSearchDelegate extends SearchDelegate {
var result = matchQuery[index];
return ListTile(
title: Text(result),
onTap: () {
close(context, result);
changeFirebase().updateColorGenre(colorText, result);}
);
},
);
}
}
\ No newline at end of file
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
class changeFirebase{
final String id = (FirebaseAuth.instance.currentUser?.uid.toString())!+'_genres';
Future<void> updateColorGenre(String colorText, String genre) async {
await FirebaseFirestore.instance.collection('classification')
.doc(id)
.update({colorText: genre});
}
String checkForNull(var document){
if(document == null){
return 'Not Selected';
}
else{
return document.toString();
}
}
bool checkIfEverythingSelected(AsyncSnapshot snapshot){
if (snapshot.data['Red'] == null){ return false;}
if (snapshot.data['Orange'] == null){ return false;}
if (snapshot.data['Yellow'] == null){ return false;}
if (snapshot.data['Green'] == null){ return false;}
if (snapshot.data['White'] == null){ return false;}
if (snapshot.data['Blue'] == null){ return false;}
if (snapshot.data['Pink'] == null){ return false;}
if (snapshot.data['Purple'] == null){ return false;}
if (snapshot.data['Brown'] == null){ return false;}
if (snapshot.data['Black'] == null){ return false;}
return true;
}
String getGenreByHex(String code){
switch (code){
case 'FF0000':
return getGenreByColor('Red');
case 'FF8800':
return getGenreByColor('Orange');
case 'FFFF00':
return getGenreByColor('Yellow');
case 'FF8800':
return getGenreByColor('Green');
case 'FFFFFF':
return getGenreByColor('White');
case '0000FF':
return getGenreByColor('Blue');
case 'FFC0CB':
return getGenreByColor('Pink');
case 'A020F0':
return getGenreByColor('Purple');
case '964B00':
return getGenreByColor('Brown');
case '000000':
return getGenreByColor('Black');
}
return '';
}
String getGenreByColor(String color){
String genre = '';
FutureBuilder<DocumentSnapshot>(
future: FirebaseFirestore.instance.collection('classification').doc(id).get(),
builder: (BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot){
genre = snapshot.data![color];
return const SizedBox();
});
return genre;
}
}
\ No newline at end of file
File moved
File moved
import 'package:ambient/registration.dart';
import 'package:ambient/widgets.dart';
import 'package:ambient/classification/classification.dart';
import 'package:ambient/loginRegister/registration.dart';
import 'package:ambient/loginRegister/widgets.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:page_transition/page_transition.dart';
import 'homepage.dart';
import '../homepage.dart';
class LoginPage extends StatefulWidget {
......@@ -18,6 +19,7 @@ class LoginPage extends StatefulWidget {
class _LoginPageState extends State<LoginPage> {
TextEditingController _passwordTextController = TextEditingController();
TextEditingController _emailTextController = TextEditingController();
bool _wrongInput = false;
@override
......@@ -26,8 +28,12 @@ class _LoginPageState extends State<LoginPage> {
return Stack(
children: <Widget>[
Image.asset("ambientL.jpeg",height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width, fit: BoxFit.cover),
Image.asset("ambientL.jpeg",
alignment: Alignment.centerLeft,
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,),
// width: MediaQuery.of(context).size.width, fit: BoxFit.cover),
Scaffold(
backgroundColor: Colors.transparent,
......@@ -36,50 +42,63 @@ class _LoginPageState extends State<LoginPage> {
child :Container(
decoration: const BoxDecoration(
),
child: SizedBox(width: 250, height: 600,
child: SizedBox(width: 250, height: 650,
child : Column(
children:[
SizedBox(height: 80,),
const Expanded(
child: Text(
'Login',
style: TextStyle(fontSize: 30.0, color: Colors.white),
'Ambient!',
style: TextStyle(fontSize: 50.0, color: Colors.white),
),),
Expanded(
child: Column(
children:[
Expanded(
child: TextField(
style: TextStyle(color: Colors.white),
controller: _emailTextController,
keyboardType: TextInputType.name,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.person, color: Colors.blueGrey),
prefixIcon: Icon(Icons.person, color: Colors.white),
hintText: 'Username',
hintStyle: TextStyle(color: Colors.white),
labelText: 'Username',
labelStyle: TextStyle(color: Colors.white),
),
),),
Expanded(
child: TextField(
style: TextStyle(color: Colors.white),
controller: _passwordTextController,
obscureText: true,
keyboardType: TextInputType.visiblePassword,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.lock_outline, color: Colors.blueGrey),
hintStyle: TextStyle(color: Colors.white),
prefixIcon: Icon(Icons.lock_outline, color: Colors.white),
hintText: 'Password',
labelText: 'Password',
labelStyle: TextStyle(color: Colors.white),
),
),),
]
)
),
_wrongInput ? const Text( 'E-Mail or password wrong',
style: TextStyle(color: Colors.red),)
: const SizedBox(),
loginRegisterButton(context, true, (){
FirebaseAuth.instance.signInWithEmailAndPassword(
email: _emailTextController.text,
password: _passwordTextController.text).then((value) {
Navigator.push(context, MaterialPageRoute(builder: (context)=>const HomePage()));
}).onError((error, stackTrace){
errorFunction("Password or email not correct");
setState(() {
_wrongInput = true;
});
});
}),
registrationPage(),
]
)
......@@ -93,7 +112,8 @@ class _LoginPageState extends State<LoginPage> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Have no account yet?" ,
style: TextStyle(color: Colors.black)),
style: TextStyle(color: Colors.white)),
SizedBox(width: 20,),
ElevatedButton(
style:ButtonStyle(backgroundColor: MaterialStatePropertyAll<Color>(Colors.white.withOpacity(0.9))),
child: const Text(
......
import 'package:ambient/loginRegister/widgets.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import '../classification/classification.dart';
import 'package:ambient/loginRegister/login.dart';
import 'package:page_transition/page_transition.dart';
class RegistrationPage extends StatefulWidget {
const RegistrationPage({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _RegistrationPage();
}
class _RegistrationPage extends State<RegistrationPage> {
TextEditingController _passwordTextController = TextEditingController();
TextEditingController _emailTextController = TextEditingController();
TextEditingController _usernameTextController = TextEditingController();
String _infoText = '';
@override
Widget build(BuildContext context) {
Firebase.initializeApp();
return Stack(
children: <Widget>[
const SizedBox(
width: double.infinity,
height: double.infinity,
child: DecoratedBox( decoration: BoxDecoration(
color: Color(0xff353444),
),
),
),
Image.asset("ambientR.jpeg",height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width),
Scaffold(
backgroundColor: Colors.transparent,
body: Center(
child :Container(
decoration: const BoxDecoration(
),
child: SizedBox(width: 250, height: 600,
child : Column(
children:[
SizedBox(height: 40,),
const Expanded(
child: Text(
'Ambient!',
style: TextStyle(fontSize: 60.0, color: Colors.white),
),),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: TextField(
controller: _usernameTextController,
style: TextStyle(color: Colors.white),
keyboardType: TextInputType.name,
decoration: InputDecoration(
prefixIcon: Icon(Icons.person, color: Colors.white),
hintText: 'Username',
hintStyle: TextStyle(color: Colors.white),
labelText: 'Username',
labelStyle: TextStyle(color: Colors.white.withOpacity(0.7))
),
),),
Expanded(
child: TextField(
controller: _emailTextController,
style: TextStyle(color: Colors.white),
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
prefixIcon: Icon(Icons.mail_outline, color: Colors.white),
hintText: 'Email',
hintStyle: TextStyle(color: Colors.white),
labelText: 'Email',
labelStyle: TextStyle(color: Colors.white.withOpacity(0.7))
),
),),
Expanded(
child: TextField(
controller: _passwordTextController,
style: TextStyle(color: Colors.white),
obscureText: true,
keyboardType: TextInputType.visiblePassword,
decoration: InputDecoration(
prefixIcon: Icon(Icons.lock_outline, color: Colors.white),
hintStyle: TextStyle(color: Colors.white),
hintText: 'Password',
labelText: 'Password',
labelStyle: TextStyle(color: Colors.white.withOpacity(0.7))
),),),
]
)
),
Text(
_infoText,
style: const TextStyle (color: Colors.red)
),
loginRegisterButton(context, false, () {
try{
FirebaseAuth.instance.createUserWithEmailAndPassword(
email: _emailTextController.text,
password: _passwordTextController.text).then((value){
createSetUp();
print ("Created new account");
Navigator.push(context, MaterialPageRoute(builder: (context)=>ClassificationPage()));
});}
on FirebaseAuthException catch(e){
if(e.code == 'ERROR_EMAIL_ALREADY_IN_USE'){
setState(() {
_infoText = 'Email already in use';
});
}
if(e.code == 'weak-password'){
setState(() {
_infoText = 'weak Password';
});}
if(e.code == 'invalid-email'){
setState(() {
_infoText = 'invalid email';
});}
else{
setState(() {
_infoText = 'invalid Input';
});
}
};
}),
SizedBox(height: 20),
loginPage(),
]
)))
))]);
}
Row loginPage(){
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Already have an account?" ,
style: TextStyle(color: Colors.white)),
SizedBox(width: 20,),
ElevatedButton(
style:ButtonStyle(backgroundColor: MaterialStatePropertyAll<Color>(Colors.white.withOpacity(0.9))),
child: const Text(
"Login",
style: TextStyle(color: Colors.indigo, fontWeight: FontWeight.bold),
),
onPressed: (){
Navigator.push(context, PageTransition(
alignment: Alignment.bottomCenter,
curve: Curves.easeInOut,
duration: Duration(milliseconds: 600),
reverseDuration: Duration(milliseconds: 600),
type: PageTransitionType.leftToRightJoined,
child: LoginPage(),
childCurrent: RegistrationPage(),
));
},
)
],
);
}
Future addDisplayName() async{
FirebaseAuth.instance.currentUser?.updateDisplayName(_usernameTextController.text);
}
Future createSetUp() async{
//final String id = '${FirebaseAuth.instance.currentUser?.uid.toString()}_genres';
final String id = (FirebaseAuth.instance.currentUser?.uid.toString())!+'_genres';
final user = FirebaseFirestore.instance.collection('classification').doc(id);
final json = {
'user' : _usernameTextController.text,
'Red' : null,
'Orange' : null,
'Yellow' : null,
'Green' : null,
'White' : null,
'Blue' : null,
'Pink' : null,
'Purple' : null,
'Brown' : null,
'Black' : null,
};
await user.set(json);
}
}
\ No newline at end of file
File moved
import 'package:ambient/Classification/classification.dart';
import 'package:ambient/LoginRegister/registration.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:ambient/emptyMoodpage.dart';
import 'package:ambient/searchpage.dart';
import 'package:ambient/widgets/MusicPlayerState.dart';
......@@ -9,6 +12,7 @@ import 'package:spotify_sdk/models/player_state.dart';
import 'package:spotify_sdk/spotify_sdk.dart';
import 'homepage.dart';
import 'LoginRegister/login.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
......
import 'package:ambient/widgets.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'classification.dart';
import 'package:ambient/login.dart';
import 'package:page_transition/page_transition.dart';
class RegistrationPage extends StatefulWidget {
const RegistrationPage({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _RegistrationPage();
}
class _RegistrationPage extends State<RegistrationPage> {
TextEditingController _passwordTextController = TextEditingController();
TextEditingController _emailTextController = TextEditingController();
TextEditingController _usernameTextController = TextEditingController();
@override
Widget build(BuildContext context) {
Firebase.initializeApp();
return Stack(
children: <Widget>[
Image.asset("ambientR.jpeg",height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width, fit: BoxFit.cover),
Scaffold(
backgroundColor: Colors.transparent,
body: Center(
child :Container(
decoration: const BoxDecoration(
),
child: SizedBox(width: 250, height: 600,
child : Column(
children:[
const Expanded(
child: Text(
'Registration',
style: TextStyle(fontSize: 30.0, color: Colors.white),
),),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: TextField(
controller: _usernameTextController,
keyboardType: TextInputType.name,
decoration: InputDecoration(
hintText: 'Username',
labelText: 'Username',
),
),),
Expanded(
child: TextField(
controller: _emailTextController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
hintText: 'Email',
labelText: 'Email',
),
),),
Expanded(
child: TextField(
controller: _passwordTextController,
obscureText: true,
keyboardType: TextInputType.visiblePassword,
decoration: InputDecoration(
hintText: 'Password',
labelText: 'Password',
),
),),
]
)
),
loginRegisterButton(context, false, () {
FirebaseAuth.instance.createUserWithEmailAndPassword(
email: _emailTextController.text,
password: _passwordTextController.text).then((value){
print ("Created new account");
Navigator.push(context, MaterialPageRoute(builder: (context)=>ClassificationPage()));
}).onError((error, stackTrace) {
print("Error ${error.toString()}");
});
//addDisplayName();
createSetUp();
}),
SizedBox(height: 20),
loginPage(),
]
)))
))]);
}
Row loginPage(){
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Already have an account?" ,
style: TextStyle(color: Colors.black)),
ElevatedButton(
style:ButtonStyle(backgroundColor: MaterialStatePropertyAll<Color>(Colors.white.withOpacity(0.9))),
child: const Text(
"Login",
style: TextStyle(color: Colors.indigo, fontWeight: FontWeight.bold),
),
onPressed: (){
Navigator.push(context, PageTransition(
alignment: Alignment.bottomCenter,
curve: Curves.easeInOut,
duration: Duration(milliseconds: 600),
reverseDuration: Duration(milliseconds: 600),
type: PageTransitionType.leftToRightJoined,
child: LoginPage(),
childCurrent: RegistrationPage(),
));
},
)
],
);
}
Future addDisplayName() async{
FirebaseAuth.instance.currentUser?.updateDisplayName(_usernameTextController.text);
}
Future createSetUp() async{
final String id = '${FirebaseAuth.instance.currentUser?.uid.toString()}_genres';
final user = FirebaseFirestore.instance.collection('classification').doc(id);
final json = {
'user' : _usernameTextController.text,
'Red' : 'Not Selected',
'Orange' : 'Not Selected',
'Yellow' : 'Not Selected',
};
await user.set(json);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment