From 0f7ba83126b6b66147ab2cd15fb3b1c23caf1e6e Mon Sep 17 00:00:00 2001 From: Madlen Ort <madlen.ort@stud.hs-hannover.de> Date: Thu, 19 Jan 2023 19:09:30 +0100 Subject: [PATCH] Weitergemacht --- lib/classification.dart | 336 ------------ .../CustomSearchDelegate.dart | 15 +- lib/classification/classification.dart | 477 ++++++++++++++++++ lib/classification/color_widgets.dart | 0 lib/firebase.dart | 75 +++ lib/{ => loginRegister}/ambientL.jpeg | Bin lib/{ => loginRegister}/ambientR.jpeg | Bin lib/{ => loginRegister}/login.dart | 46 +- lib/loginRegister/registration.dart | 205 ++++++++ lib/{ => loginRegister}/widgets.dart | 0 lib/main.dart | 6 +- lib/registration.dart | 149 ------ 12 files changed, 806 insertions(+), 503 deletions(-) delete mode 100644 lib/classification.dart rename lib/{ => classification}/CustomSearchDelegate.dart (91%) create mode 100644 lib/classification/classification.dart create mode 100644 lib/classification/color_widgets.dart create mode 100644 lib/firebase.dart rename lib/{ => loginRegister}/ambientL.jpeg (100%) rename lib/{ => loginRegister}/ambientR.jpeg (100%) rename lib/{ => loginRegister}/login.dart (69%) create mode 100644 lib/loginRegister/registration.dart rename lib/{ => loginRegister}/widgets.dart (100%) delete mode 100644 lib/registration.dart diff --git a/lib/classification.dart b/lib/classification.dart deleted file mode 100644 index e265738..0000000 --- a/lib/classification.dart +++ /dev/null @@ -1,336 +0,0 @@ -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 'package:flutter_custom_clippers/flutter_custom_clippers.dart'; -import 'CustomSearchDelegate.dart'; -import 'homepage.dart'; - -class ClassificationPage extends StatefulWidget { - const ClassificationPage({Key? key}) : super(key: key); - - @override - State<StatefulWidget> createState() => _ClassificationPageState(); - -} - -class _ClassificationPageState extends State<ClassificationPage> { - - Color _ambientBackgroundColor = Colors.grey.withOpacity(0.5); - Color _ambientHeader = Colors.white; - - String genreValue = ''; - - bool _redSelected = false; - bool _orangeSelected = false; - bool _yellowSelected = false; - bool _greenSelected = false; - - void _redContainerWasTapped() { - setState(() => _redSelected = !_redSelected); - //if redSelected = true dann rot, sonst wieder grau - _ambientBackgroundColor = Colors.red; - if (!_redSelected){_ambientBackgroundColor = Colors.grey.withOpacity(0.5);} - } - - void _orangeContainerWasTapped() { - setState(() => _orangeSelected = !_orangeSelected); - _ambientBackgroundColor = Colors.orange; - if (!_orangeSelected){_ambientBackgroundColor = Colors.grey.withOpacity(0.5);} - } - void _yellowContainerWasTapped() { - setState(() => _yellowSelected = !_yellowSelected); - _ambientBackgroundColor = Colors.yellow; - if (!_yellowSelected){_ambientBackgroundColor = Colors.grey.withOpacity(0.5);} - } - void _greenContainerWasTapped() { - setState(() => _greenSelected = !_greenSelected); - _ambientBackgroundColor = Colors.green; - if (!_greenSelected){_ambientBackgroundColor = Colors.grey.withOpacity(0.5);} - } - - @override - Widget build(BuildContext context) { - Firebase.initializeApp(); - print("User"); - print(FirebaseAuth.instance.currentUser?.uid.toString()); - return Scaffold( - resizeToAvoidBottomInset: false, - body: Container( - child: Column( - children: [ - ClipPath( - clipper: WaveClipperTwo(flip: true), - child: Container( - height: 140, - color: _ambientBackgroundColor, - child: Center( - child: Text( - 'Ambient!', - style: TextStyle( - fontSize: 40.0, color: _ambientHeader), - ), - ),),), - Expanded( - child: ListView( - children: <Widget>[ - SizedBox(height: 20,), - GestureDetector( - onTap: _redContainerWasTapped, - child: Container( - //if Datenbank bei rot = 0, dann not selected, ansonsten change - child: _redSelected ? - selectedColor( - "Red", Colors.red, "Rot Rec 1", "Rot Rec 2", - "Rot Rec 3") : noSelection("Red") - ) - ,), - SizedBox(height: 20,), - GestureDetector( - onTap: _orangeContainerWasTapped, - child: Container( - child: _orangeSelected ? - selectedColor( - "Orange", Colors.orange, "Orange 1", - "Orange 2", "Orange 3") : noSelection( - "Orange") - ) - ,), - SizedBox(height: 20,), - GestureDetector( - onTap: _yellowContainerWasTapped, - child: Container( - child: _yellowSelected ? - selectedColor( - "Yellow", Colors.yellow, "Yellow1", - "Yellow1", "Yellow1") : noSelection( - "Yellow") - ) - ,), - SizedBox(height: 20,), - GestureDetector( - onTap: _greenContainerWasTapped, - child: Container( - child: _greenSelected ? - selectedColor( - "Green", Colors.green, "Green1", - "Green2", "Green3") : noSelection( - "Green") - ) - ,), - SizedBox(height: 20,), - ElevatedButton( - style:ButtonStyle(backgroundColor: MaterialStatePropertyAll<Color>(Colors.white.withOpacity(0.9))), - child: const Text( - "Skip", - style: TextStyle(color: Colors.indigo, fontWeight: FontWeight.bold), - ), - onPressed: (){ - Navigator.push(context, MaterialPageRoute(builder: (context)=>const HomePage())); - }), - ]), - ), - ] - ) - )); - } - - //wenn die Farbe nicht ausgewählt ist, wird kein Genre-Auswahl dargestellt und die Farben sind auf grau - Column noSelection(String colorText) { - return Column( - children: [ - Row( - children: [ - SizedBox(width: 30, height: 50), - Text(colorText, - style: TextStyle(fontSize: 30, color: Colors.grey)), - ] - ), - Align( - alignment: Alignment.center, - child: Row( - children: [ - SizedBox(width: 30), - Container( - width: 340, - decoration: BoxDecoration( - color: Colors.transparent, - border: Border.all( - color: Colors.grey, - width: 1), - borderRadius: BorderRadius.circular(10), - ), - child: - Text(checkForGenre(colorText).toString(), textAlign: TextAlign.center, - style: TextStyle(fontSize: 20, color: Colors.grey),) - ) - ] - ) - ) - ]); -} - - Column selectedColor(String colorText, Color color, String rec1, String rec2, - String rec3) { - return Column( - children: [ - Row( - children: [ - SizedBox(width: 30, height: 50), - Text(colorText, style: TextStyle(fontSize: 30, color: color)), - ] - ), - selectedGenre(colorText, color, rec1, rec2, rec3), - ]); - } - - Align selectedGenre(String colorText, Color color, String rec1, String rec2, - String rec3) { - return Align( - alignment: Alignment.center, - child: Column( - children: [ - Row( - children: [ - SizedBox(width: 30), - Container( - width: 340, - decoration: BoxDecoration( - color: Colors.transparent, - border: Border.all( - color: color, - width: 1), - borderRadius: BorderRadius.circular(10), - ), - child: - Text(checkForGenre(colorText).toString(), textAlign: TextAlign.center, - style: TextStyle(fontSize: 20, color: Colors.grey),) - ), - ] - ), - SizedBox(height: 30), - Container( - width: 340, - // alignment: Alignment.center, - decoration: BoxDecoration( - color: color, - borderRadius: BorderRadius.circular(10), - boxShadow: [ - BoxShadow( - color: Colors.grey.withOpacity(0.5), - blurRadius: 10.0, - spreadRadius: 2.0, - offset: Offset(0.0, 0.0), - ) - ], - ), - child: Column( - children: [ - SizedBox(height: 20,), - Container( - width: 290, - child: TextField( - decoration: InputDecoration( - prefixIcon: Icon( - Icons.search, color: Colors.white.withOpacity(0.7)), - hintText: 'search for genres', - hintStyle: TextStyle( - fontSize: 20, color: Colors.white.withOpacity(0.7))), - style: TextStyle(fontSize: 20, color: Colors.white), - onTap: () { - // method to show the search bar - showSearch( - context: context, - // delegate to customize the search bar - delegate: CustomSearchDelegate(), - ); - }, - ), - ), - SizedBox(height: 50), - Text("Recommendation", style: TextStyle( - fontSize: 20, color: Colors.white.withOpacity(0.7))), - Column( - children: [ - SizedBox(height: 20,), - Row( - children: [ - SizedBox(width: 40,), - recommendationLabel(colorText, rec1), - ] - ), - SizedBox(height: 20,), - Row( - children: [ - SizedBox(width: 40,), - recommendationLabel(colorText, rec1), - ] - ), - SizedBox(height: 20,), - Row( - children: [ - SizedBox(width: 40,), - recommendationLabel(colorText, rec1), - ] - ), - SizedBox(height: 50,) - ] - ) - ] - ) - - ) - ])); - } - - GestureDetector recommendationLabel(String colorText, String rec) { - return GestureDetector( - onTap: () => updateColorGenre(colorText, rec), - child:Container( - child: Row( - children: [ - Container( - width: 240, - height: 40, - decoration: BoxDecoration( - color: Colors.white.withOpacity(0.3), - borderRadius: BorderRadius.circular(10), - ), - child: Align( - alignment: Alignment.center, - child: Text - (rec, textAlign: TextAlign.center, - style: TextStyle(fontSize: 20, color: Colors.white),) - ), - ) - ] - ) - ), - ); - } - - Future<void> updateColorGenre(String colorText, String genre) async { - String id = await'${FirebaseAuth.instance.currentUser?.uid.toString()}_genres'; - FirebaseFirestore.instance.collection('classification') - .doc(id) - .update({colorText: genre}); - closeAll(); - } - - Future<String> checkForGenre(String colorText) async { - String id = '${FirebaseAuth.instance.currentUser?.uid.toString()}_genres'; - var document = FirebaseFirestore.instance.collection('classification').doc(id); - var snapshot = await document.get(); - //snapshot.data(); - //if(snapshot.data()?.containsKey(colorText)){ - - return await snapshot.get(colorText); - } - - closeAll(){ - _redSelected = false; - _orangeSelected = false; - } - - -} diff --git a/lib/CustomSearchDelegate.dart b/lib/classification/CustomSearchDelegate.dart similarity index 91% rename from lib/CustomSearchDelegate.dart rename to lib/classification/CustomSearchDelegate.dart index af296d3..8fdb5bf 100644 --- a/lib/CustomSearchDelegate.dart +++ b/lib/classification/CustomSearchDelegate.dart @@ -1,6 +1,12 @@ 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 diff --git a/lib/classification/classification.dart b/lib/classification/classification.dart new file mode 100644 index 0000000..e0014df --- /dev/null +++ b/lib/classification/classification.dart @@ -0,0 +1,477 @@ +import 'package:ambient/firebase.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 'package:flutter_custom_clippers/flutter_custom_clippers.dart'; +import 'CustomSearchDelegate.dart'; +import '../homepage.dart'; + +class ClassificationPage extends StatefulWidget { + const ClassificationPage({Key? key}) : super(key: key); + + @override + State<StatefulWidget> createState() => _ClassificationPageState(); + + } + +class _ClassificationPageState extends State<ClassificationPage> { + + final String id = (FirebaseAuth.instance.currentUser?.uid.toString())!+'_genres'; + + + Color _ambientBackgroundColor = Colors.grey.withOpacity(0.5); + Color _ambientHeader = Colors.white; + + String genreValue = ''; + + bool _redSelected = false; + bool _orangeSelected = false; + bool _yellowSelected = false; + bool _greenSelected = false; + bool _whiteSelected = false; + bool _blueSelected = false; + bool _pinkSelected = false; + bool _purpleSelected = false; + bool _brownSelected = false; + bool _blackSelected = false; + + bool _errorText = false; + + @override + Widget build(BuildContext context) { + Firebase.initializeApp(); + print("User"); + print(FirebaseAuth.instance.currentUser?.uid.toString()); + return Scaffold( + resizeToAvoidBottomInset: false, + body: Container( + child: Column( + children: [ + ClipPath( + clipper: WaveClipperTwo(flip: true), + child: Container( + height: 140, + color: _ambientBackgroundColor, + child: Center( + child: Text( + 'Ambient!', + style: TextStyle( + fontSize: 40.0, color: _ambientHeader), + ), + ),),), + Expanded( + child: ListView( + children: <Widget>[ + const SizedBox(height: 20,), + GestureDetector( + onTap: (){ + if(!_redSelected){closeAll(); setState(() => _redSelected = true); } + else{closeAll();} + _ambientBackgroundColor = Colors.red; + if (!_redSelected){_ambientBackgroundColor = Colors.grey.withOpacity(0.5);}}, + child: Container( + child: _redSelected ? + selectedColor("Red", Colors.red, Colors.white.withOpacity(0.7), + "rock","latin", "blues", + 'Starke Emotionen, Liebe, Energie') : noSelection("Red") + ) + ,), + const SizedBox(height: 20,), + GestureDetector( + onTap: (){ + if(!_orangeSelected){closeAll(); setState(() => _orangeSelected = true); } + else{closeAll();} + _ambientBackgroundColor = Colors.orange; + if (!_orangeSelected){_ambientBackgroundColor = Colors.grey.withOpacity(0.5);}}, + child: Container( + child: _orangeSelected ? + selectedColor("Orange", Colors.orange, Colors.white.withOpacity(0.7), + "soul", "jazz", "Orange 3", 'Wärme, Energie, Herbst') : noSelection("Orange") + ) + ,), + const SizedBox(height: 20,), + GestureDetector( + onTap: () { + if(!_yellowSelected){closeAll(); setState(() => _yellowSelected = true); } + else{closeAll();} + _ambientBackgroundColor = Colors.yellow; + if (!_yellowSelected){_ambientBackgroundColor = Colors.grey.withOpacity(0.5);}}, + child: Container( + child: _yellowSelected ? + selectedColor("Yellow", Colors.yellow, Colors.white, + "pop", "funk", "country", 'Freude, Optimismus, Wärme') : noSelection("Yellow") + ) + ,), + const SizedBox(height: 20,), + GestureDetector( + onTap: () { + if(!_greenSelected){closeAll(); setState(() => _greenSelected = true); } + else{closeAll();} + _ambientBackgroundColor = Colors.green; + if (!_greenSelected){_ambientBackgroundColor = Colors.grey.withOpacity(0.5);}}, + child: Container( + child: _greenSelected ? + selectedColor("Green", Colors.green, Colors.white.withOpacity(0.7), + "ambient", "classical", "new-age", 'Ruhe, Wachstum, Natur') : noSelection("Green") + ) + ,), + const SizedBox(height: 20,), + GestureDetector( + onTap: (){ + if(!_whiteSelected){closeAll(); setState(() => _whiteSelected = true); } + else{closeAll();} + _ambientBackgroundColor = Colors.white60; + if (!_whiteSelected){_ambientBackgroundColor = Colors.grey.withOpacity(0.5);}}, + child: Container( + child: _whiteSelected ? + selectedColor("White", Colors.white60, Colors.grey, + "classical", "ambient", "piano", 'Reinheit, Frieden, Gelassenheit') : noSelection("White") + ) + ,), + const SizedBox(height: 20,), + GestureDetector( + onTap: () { + if(!_blueSelected){closeAll(); setState(() => _blueSelected = true); } + else{closeAll();} + _ambientBackgroundColor = Colors.blue; + if (!_blueSelected){_ambientBackgroundColor = Colors.grey.withOpacity(0.5);}}, + child: Container( + child: _blueSelected ? + selectedColor( "Blue", Colors.blue, Colors.white.withOpacity(0.7), + "blues", "rainy-day", "indie-pop", 'Ruhe, Gelassenheit, Traurigkeit') : noSelection("Blue") + ) + ,), + const SizedBox(height: 20,), + GestureDetector( + onTap: () { + if(!_pinkSelected){closeAll(); setState(() => _pinkSelected = true); } + else{closeAll();} + _ambientBackgroundColor = Colors.pinkAccent; + if (!_pinkSelected){_ambientBackgroundColor = Colors.grey.withOpacity(0.5);}}, + child: Container( + child: _pinkSelected ? + selectedColor( + "Pink", Colors.pink, Colors.white.withOpacity(0.7), + "pop", "k-pop", "r-n-b", 'Romantik, Anmut, Nostalgie') : noSelection("Pink") + ) + ,), + const SizedBox(height: 20,), + GestureDetector( + onTap: () { + if(!_purpleSelected){closeAll(); setState(() => _purpleSelected = true); } + else{closeAll();} + _ambientBackgroundColor = Colors.purple; + if (!_purpleSelected){_ambientBackgroundColor = Colors.grey.withOpacity(0.5);}}, + child: Container( + child: _purpleSelected ? + selectedColor("Purple", Colors.purple, Colors.white.withOpacity(0.7), + "rock", "classical", "hip-hop", 'Luxus, Spiritualität, Ambition') : noSelection("Purple") + ) + ,), + const SizedBox(height: 20,), + GestureDetector( + onTap: () { + if(!_brownSelected){closeAll(); setState(() => _brownSelected = true); } + else{closeAll();} + _ambientBackgroundColor = Colors.brown; + if (!_brownSelected){_ambientBackgroundColor = Colors.grey.withOpacity(0.5);}}, + child: Container( + child: _brownSelected ? + selectedColor("Brown", Colors.brown, Colors.white.withOpacity(0.7), + "country", "Brown2", "Brown3", 'info') : noSelection("Brown") + ) + ,), + const SizedBox(height: 20,), + GestureDetector( + onTap: () { + if(!_blackSelected){closeAll(); setState(() => _blackSelected = true); } + else{closeAll();} + _ambientBackgroundColor = Colors.black54; + if (!_blackSelected){_ambientBackgroundColor = Colors.grey.withOpacity(0.5);}}, + child: Container( + child: _blackSelected ? + selectedColor("Black", Colors.black54, Colors.white.withOpacity(0.7), "Black1", "Black2", "Black3", 'info') : noSelection("Black") + ) + ,), + const SizedBox(height: 20,), + SizedBox( + width: 100, + child : StreamBuilder( + stream: FirebaseFirestore.instance.collection('classification').doc(id).snapshots(), + builder: (BuildContext context, + AsyncSnapshot snapshot) { + return ElevatedButton( + style:ButtonStyle(backgroundColor: MaterialStatePropertyAll<Color>(Colors.white.withOpacity(0.9))), + child: const Text( + "Save", + style: TextStyle(color: Colors.indigo, fontWeight: FontWeight.bold),), + onPressed: () { + print(changeFirebase().checkIfEverythingSelected(snapshot).toString()); + if (changeFirebase().checkIfEverythingSelected(snapshot)) { + Navigator.push(context, MaterialPageRoute(builder: (context) => HomePage())); + } + else{ + setState(() { + _errorText = true; + }); + } + }); + })), + Container( + child: _errorText ? + const Text('Not everything is selected!', + textAlign: TextAlign.center, + style: TextStyle( fontSize: 20, color: Colors.red),) + : null + ), + SizedBox(height: 40,) + ]), + ), + ] + ) + )); + } + + Text errorText(){ + return const Text( + 'Not Everything is selected', + style: TextStyle(fontSize: 20, color: Colors.red) + ); + } + //wenn die Farbe nicht ausgewählt ist, wird kein Genre-Auswahl dargestellt und die Farben sind grau + Column noSelection(String colorText) { + return Column( + children: [ + Row( + children: [ + const SizedBox(width: 30, height: 50), + Text(colorText, + style: const TextStyle(fontSize: 30, color: Colors.grey)), + ] + ), + Align( + alignment: Alignment.center, + child: Row( + children: [ + const SizedBox(width: 30), + Container( + width: 340, + decoration: BoxDecoration( + color: Colors.transparent, + border: Border.all( + color: Colors.grey, + width: 1), + borderRadius: BorderRadius.circular(10), + ), + child: StreamBuilder( + stream: FirebaseFirestore.instance.collection('classification').doc(id).snapshots(), + builder: (BuildContext context, AsyncSnapshot snapshot){ + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center( + child: CircularProgressIndicator(), + ); + } + return + Text(changeFirebase().checkForNull(snapshot.data.data()[colorText]), textAlign: TextAlign.center, + style: const TextStyle(fontSize: 20, color: Colors.grey),); + } + ) + ) + ] + ) + ) + ]); +} + + Column selectedColor(String colorText, Color color, Color textColor, String rec1, String rec2, String rec3, String infoText) { + return Column( + children: [ + Row( + children: [ + const SizedBox(width: 30, height: 50), + Text(colorText, style: TextStyle(fontSize: 30, color: color)), + IconButton(onPressed:(){ + _showMyDialog(colorText, infoText); + }, + alignment: Alignment.centerRight, + icon: Icon( Icons.info_outline, color: color), + ), + ],), + selectedGenre(colorText, color, textColor, rec1, rec2, rec3), + ]); + } + + Align selectedGenre(String colorText, Color color, Color textColor, String rec1, String rec2, + String rec3) { + return Align( + alignment: Alignment.center, + child: Column( + children: [ + Row( + children: [ + const SizedBox(width: 30), + Container( + width: 340, + decoration: BoxDecoration( + color: Colors.transparent, + border: Border.all( + color: color, + width: 1), + borderRadius: BorderRadius.circular(10), + ), + child: + StreamBuilder( + stream: FirebaseFirestore.instance.collection('classification').doc(id).snapshots(), + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center( + child: CircularProgressIndicator(), + ); + } + return + Text(changeFirebase().checkForNull(snapshot.data.data()[colorText]), textAlign: TextAlign.center, + style: TextStyle(color: color, fontSize: 20),); + } + ), + ) ] + ), + const SizedBox(height: 30), + Container( + width: 340, + // alignment: Alignment.center, + decoration: BoxDecoration( + color: color, + borderRadius: BorderRadius.circular(10), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + blurRadius: 10.0, + spreadRadius: 2.0, + offset: const Offset(0.0, 0.0), + ) + ], + ), + child: Column( + children: [ + const SizedBox(height: 20,), + Container( + width: 290, + child: TextField( + decoration: InputDecoration( + prefixIcon: Icon( + Icons.search, color: textColor), + hintText: 'search for genres', + hintStyle: TextStyle( + fontSize: 20, color: textColor)), + style: TextStyle(fontSize: 20, color: textColor), + onTap: () { + showSearch( + context: context, + delegate: CustomSearchDelegate(colorText), + ); + changeFirebase().updateColorGenre(colorText, genreValue);}, + ), + ), + const SizedBox(height: 50), + Text("Recommendation", style: TextStyle( + fontSize: 20, color: textColor)), + Column( + children: [ + const SizedBox(height: 20,), + Row( + children: [ + const SizedBox(width: 40,), + recommendationLabel(colorText, rec1, textColor), + ] + ), + const SizedBox(height: 20,), + Row( + children: [ + const SizedBox(width: 40,), + recommendationLabel(colorText, rec2, textColor), + ] + ), + const SizedBox(height: 20,), + Row( + children: [ + const SizedBox(width: 40,), + recommendationLabel(colorText, rec3, textColor), + ] + ), + const SizedBox(height: 50,) + ] + ) + ] + ) + + ) + ])); + } + + GestureDetector recommendationLabel(String colorText, String rec, Color textColor) { + return GestureDetector( + onTap: () => changeFirebase().updateColorGenre(colorText, rec), + child:Container( + child: Row( + children: [ + Container( + width: 240, + height: 40, + decoration: BoxDecoration( + color: Colors.white.withOpacity(0.3), + borderRadius: BorderRadius.circular(10), + ), + child: Align( + alignment: Alignment.center, + child: Text + (rec, textAlign: TextAlign.center, + style: TextStyle(fontSize: 20, color: textColor) + ), + ) + )] + ) + ), + ); + } + + Future<void> _showMyDialog(String colorText, String infoText) { + return showDialog<void>( + context: context, + barrierDismissible: false, // user must tap button! + builder: (BuildContext context) { + return AlertDialog( + title: Text (colorText), + content: SingleChildScrollView( + child: ListBody( + children: <Widget>[ + Text(infoText), + ], + ), + ), + actions: <Widget>[ + TextButton( + child: const Text('Okay'), + onPressed: () { + Navigator.of(context).pop(); + },), + ],); + },);} + + closeAll(){ + _ambientBackgroundColor = Colors.grey.withOpacity(0.5); + setState(() { + _redSelected = false; + _orangeSelected = false; + _yellowSelected = false; + _greenSelected = false; + _whiteSelected = false; + _blueSelected = false; + _pinkSelected = false; + _purpleSelected = false; + _brownSelected = false; + _blackSelected = false; + }); + _ambientBackgroundColor = Colors.grey.withOpacity(0.5); + } +} diff --git a/lib/classification/color_widgets.dart b/lib/classification/color_widgets.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/firebase.dart b/lib/firebase.dart new file mode 100644 index 0000000..88fe12c --- /dev/null +++ b/lib/firebase.dart @@ -0,0 +1,75 @@ +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 diff --git a/lib/ambientL.jpeg b/lib/loginRegister/ambientL.jpeg similarity index 100% rename from lib/ambientL.jpeg rename to lib/loginRegister/ambientL.jpeg diff --git a/lib/ambientR.jpeg b/lib/loginRegister/ambientR.jpeg similarity index 100% rename from lib/ambientR.jpeg rename to lib/loginRegister/ambientR.jpeg diff --git a/lib/login.dart b/lib/loginRegister/login.dart similarity index 69% rename from lib/login.dart rename to lib/loginRegister/login.dart index 508804f..e91eaa7 100644 --- a/lib/login.dart +++ b/lib/loginRegister/login.dart @@ -1,11 +1,12 @@ -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"); + }).onError((error, stackTrace){ + 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( diff --git a/lib/loginRegister/registration.dart b/lib/loginRegister/registration.dart new file mode 100644 index 0000000..986030b --- /dev/null +++ b/lib/loginRegister/registration.dart @@ -0,0 +1,205 @@ +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 diff --git a/lib/widgets.dart b/lib/loginRegister/widgets.dart similarity index 100% rename from lib/widgets.dart rename to lib/loginRegister/widgets.dart diff --git a/lib/main.dart b/lib/main.dart index e6c4037..aaeb589 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,10 +1,10 @@ -import 'package:ambient/classification.dart'; -import 'package:ambient/registration.dart'; +import 'package:ambient/Classification/classification.dart'; +import 'package:ambient/LoginRegister/registration.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; import 'homepage.dart'; -import 'login.dart'; +import 'LoginRegister/login.dart'; void main() async { diff --git a/lib/registration.dart b/lib/registration.dart deleted file mode 100644 index 4e251a6..0000000 --- a/lib/registration.dart +++ /dev/null @@ -1,149 +0,0 @@ -import 'package:ambient/homepage.dart'; -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 -- GitLab