From 1abe3368732940b467d76a698f2ac4c1897a0023 Mon Sep 17 00:00:00 2001 From: Schummi C Date: Thu, 11 May 2023 20:17:24 +0200 Subject: [PATCH 1/2] Log In Page Layout erstellt --- lib/home.dart | 112 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 86 insertions(+), 26 deletions(-) diff --git a/lib/home.dart b/lib/home.dart index aa89715..21c8436 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -1,22 +1,32 @@ -import 'package:oggauergemeindetrommler/AddPage.dart'; import 'package:flutter/material.dart'; +import 'AddPage.dart'; import 'UserDefinedList.dart'; class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); + const MyHomePage({Key? key, required this.title}); final String title; + //final TextEditingController _emailController = TextEditingController(); @override State createState() => _MyHomePageState(); } +bool isValidEmail(String email) { + // Hier kannst du deine Validierungslogik implementieren + // Rückgabe true, wenn die E-Mail gültig ist, andernfalls false + // Beispiel: + return RegExp(r'^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$').hasMatch(email); +} + class _MyHomePageState extends State { int _selectedIndex = 0; - bool login = false; + final TextEditingController _emailController = TextEditingController(); + final GlobalKey _scaffoldKey = GlobalKey(); + static const TextStyle optionStyle = - TextStyle(fontSize: 30, fontWeight: FontWeight.bold); + TextStyle(fontSize: 30, fontWeight: FontWeight.bold); void _onItemTapped(int index) { setState(() { @@ -24,32 +34,81 @@ class _MyHomePageState extends State { }); } - void setLogin(bool value) { - setState(() { - login = value; - }); - } - @override Widget build(BuildContext context) { final List widgetOptions = [ const GenericList(collectionName: 'CitizensForum'), const GenericList(collectionName: 'News'), const GenericList(collectionName: 'Issues'), - Column(mainAxisAlignment: MainAxisAlignment.center, children: [ - ElevatedButton( - child: Text(login ? 'Logout' : 'Login'), - onPressed: () { - setLogin(!login); - }, - ), - const Text( - 'Index 2: Profil', - style: optionStyle, - ), - ]) + Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const SizedBox(height: 16), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 32), + child: Column( + children: [ + TextFormField( + controller: _emailController, + decoration: InputDecoration( + labelText: 'E-Mail', + ), + + validator: (value) { + if (value!.isEmpty) { + return 'Bitte geben Sie eine E-Mail-Adresse ein.'; + } else if (!isValidEmail(value)) { + return 'Bitte geben Sie eine gültige E-Mail-Adresse ein.'; + } + return null; + }, + ), + + const SizedBox(height: 16), + TextFormField( + obscureText: true, + decoration: const InputDecoration( + labelText: 'Passwort', + ), + ), + ElevatedButton( + onPressed: () { + String email = _emailController.text; + if (isValidEmail(email)) { + // E-Mail ist gültig, führe die entsprechende Aktion aus + } else {/* + _scaffoldKey.currentState!.showSnackBar( + SnackBar( + content: Text('Ungültige E-Mail-Adresse'), + duration: Duration(seconds: 2), + ), + ); + */ + } + }, + child: Text('Anmelden'), + ), + SizedBox(height: 16), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text('Noch kein Konto?'), + TextButton( + onPressed: () { + // Navigiere zur Registrierungsseite + }, + child: Text('Registrieren'), + ), + ], + ), + ], + ), + ), + ], + ), ]; + return Scaffold( appBar: AppBar( title: const Text('Oggauer Gemeinde Trommler'), @@ -57,17 +116,18 @@ class _MyHomePageState extends State { body: Center( child: widgetOptions.elementAt(_selectedIndex), ), - floatingActionButton: _selectedIndex == 3 // Wenn der ausgewählte Index 3 ist, also auf dem Profil-Widget - ? null // Zeigt keinen Button an + floatingActionButton: _selectedIndex == 3 + ? null : FloatingActionButton( onPressed: () { Navigator.push( context, MaterialPageRoute( - builder: (context) => AddScreen(initialIndex: _selectedIndex)), + builder: (context) => AddScreen(initialIndex: _selectedIndex), + ), ); }, - tooltip: "Add", + tooltip: 'Add', child: const Icon(Icons.add), ), bottomNavigationBar: BottomNavigationBar( From 2ee134e28301e2ce7f6c218067cc93acbde8bd89 Mon Sep 17 00:00:00 2001 From: Nicolas Gruber Date: Sat, 13 May 2023 13:30:57 +0200 Subject: [PATCH 2/2] addet login code to LoginPage.dart, fixed valid email snackbar --- lib/LoginPage.dart | 95 ++++++++++++++++++++++++++++++++++++++++ lib/home.dart | 107 ++++++--------------------------------------- 2 files changed, 108 insertions(+), 94 deletions(-) create mode 100644 lib/LoginPage.dart diff --git a/lib/LoginPage.dart b/lib/LoginPage.dart new file mode 100644 index 0000000..fdca8a1 --- /dev/null +++ b/lib/LoginPage.dart @@ -0,0 +1,95 @@ +import 'package:flutter/material.dart'; + +class LoginPage extends StatefulWidget { + LoginPage({Key? key}) : super(key: key); + + @override + _LoginPageState createState() => _LoginPageState(); +} + +class _LoginPageState extends State { + final _emailController = TextEditingController(); + + @override + void dispose() { + _emailController.dispose(); + super.dispose(); + } + + bool isValidEmail(String email) { + // Hier kannst du deine Validierungslogik implementieren + // Rückgabe true, wenn die E-Mail gültig ist, andernfalls false + // Beispiel: + return RegExp(r'^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$').hasMatch(email); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const SizedBox(height: 16), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 32), + child: Column( + children: [ + TextFormField( + controller: _emailController, + decoration: const InputDecoration( + labelText: 'E-Mail', + ), + validator: (value) { + if (value!.isEmpty) { + return 'Bitte geben Sie eine E-Mail-Adresse ein.'; + } else if (!isValidEmail(value)) { + return 'Bitte geben Sie eine gültige E-Mail-Adresse ein.'; + } + return null; + }, + ), + const SizedBox(height: 16), + TextFormField( + obscureText: true, + decoration: const InputDecoration( + labelText: 'Passwort', + ), + ), + ElevatedButton( + onPressed: () { + String email = _emailController.text; + if (isValidEmail(email)) { + // E-Mail ist gültig, führe die entsprechende Aktion aus + } else { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Ungültige E-Mail-Adresse'), + duration: Duration(seconds: 2), + ), + ); + } + }, + child: const Text('Anmelden'), + ), + const SizedBox(height: 16), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text('Noch kein Konto?'), + TextButton( + onPressed: () { + // Navigiere zur Registrierungsseite + }, + child: const Text('Registrieren'), + ), + ], + ), + ], + ), + ), + ], + ), + ); + } +} + diff --git a/lib/home.dart b/lib/home.dart index 21c8436..ae78e26 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:oggauergemeindetrommler/LoginPage.dart'; import 'AddPage.dart'; import 'UserDefinedList.dart'; @@ -6,28 +7,11 @@ class MyHomePage extends StatefulWidget { const MyHomePage({Key? key, required this.title}); final String title; - //final TextEditingController _emailController = TextEditingController(); - @override State createState() => _MyHomePageState(); } - -bool isValidEmail(String email) { - // Hier kannst du deine Validierungslogik implementieren - // Rückgabe true, wenn die E-Mail gültig ist, andernfalls false - // Beispiel: - return RegExp(r'^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$').hasMatch(email); -} - class _MyHomePageState extends State { int _selectedIndex = 0; - final TextEditingController _emailController = TextEditingController(); - final GlobalKey _scaffoldKey = GlobalKey(); - - - static const TextStyle optionStyle = - TextStyle(fontSize: 30, fontWeight: FontWeight.bold); - void _onItemTapped(int index) { setState(() { _selectedIndex = index; @@ -40,75 +24,9 @@ class _MyHomePageState extends State { const GenericList(collectionName: 'CitizensForum'), const GenericList(collectionName: 'News'), const GenericList(collectionName: 'Issues'), - Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const SizedBox(height: 16), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 32), - child: Column( - children: [ - TextFormField( - controller: _emailController, - decoration: InputDecoration( - labelText: 'E-Mail', - ), - - validator: (value) { - if (value!.isEmpty) { - return 'Bitte geben Sie eine E-Mail-Adresse ein.'; - } else if (!isValidEmail(value)) { - return 'Bitte geben Sie eine gültige E-Mail-Adresse ein.'; - } - return null; - }, - ), - - const SizedBox(height: 16), - TextFormField( - obscureText: true, - decoration: const InputDecoration( - labelText: 'Passwort', - ), - ), - ElevatedButton( - onPressed: () { - String email = _emailController.text; - if (isValidEmail(email)) { - // E-Mail ist gültig, führe die entsprechende Aktion aus - } else {/* - _scaffoldKey.currentState!.showSnackBar( - SnackBar( - content: Text('Ungültige E-Mail-Adresse'), - duration: Duration(seconds: 2), - ), - ); - */ - } - }, - child: Text('Anmelden'), - ), - SizedBox(height: 16), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text('Noch kein Konto?'), - TextButton( - onPressed: () { - // Navigiere zur Registrierungsseite - }, - child: Text('Registrieren'), - ), - ], - ), - ], - ), - ), - ], - ), + LoginPage() ]; - return Scaffold( appBar: AppBar( title: const Text('Oggauer Gemeinde Trommler'), @@ -119,17 +37,18 @@ class _MyHomePageState extends State { floatingActionButton: _selectedIndex == 3 ? null : FloatingActionButton( - onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => AddScreen(initialIndex: _selectedIndex), + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + AddScreen(initialIndex: _selectedIndex), + ), + ); + }, + tooltip: 'Add', + child: const Icon(Icons.add), ), - ); - }, - tooltip: 'Add', - child: const Icon(Icons.add), - ), bottomNavigationBar: BottomNavigationBar( items: const [ BottomNavigationBarItem(