addet login code to LoginPage.dart, fixed valid email snackbar
This commit is contained in:
@@ -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<LoginPage> {
|
||||||
|
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: <Widget>[
|
||||||
|
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'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+13
-94
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:oggauergemeindetrommler/LoginPage.dart';
|
||||||
import 'AddPage.dart';
|
import 'AddPage.dart';
|
||||||
import 'UserDefinedList.dart';
|
import 'UserDefinedList.dart';
|
||||||
|
|
||||||
@@ -6,28 +7,11 @@ class MyHomePage extends StatefulWidget {
|
|||||||
const MyHomePage({Key? key, required this.title});
|
const MyHomePage({Key? key, required this.title});
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
//final TextEditingController _emailController = TextEditingController();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<MyHomePage> createState() => _MyHomePageState();
|
State<MyHomePage> 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<MyHomePage> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
int _selectedIndex = 0;
|
int _selectedIndex = 0;
|
||||||
final TextEditingController _emailController = TextEditingController();
|
|
||||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
|
||||||
|
|
||||||
|
|
||||||
static const TextStyle optionStyle =
|
|
||||||
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
|
|
||||||
|
|
||||||
void _onItemTapped(int index) {
|
void _onItemTapped(int index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedIndex = index;
|
_selectedIndex = index;
|
||||||
@@ -40,75 +24,9 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
const GenericList(collectionName: 'CitizensForum'),
|
const GenericList(collectionName: 'CitizensForum'),
|
||||||
const GenericList(collectionName: 'News'),
|
const GenericList(collectionName: 'News'),
|
||||||
const GenericList(collectionName: 'Issues'),
|
const GenericList(collectionName: 'Issues'),
|
||||||
Column(
|
LoginPage()
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: <Widget>[
|
|
||||||
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(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Oggauer Gemeinde Trommler'),
|
title: const Text('Oggauer Gemeinde Trommler'),
|
||||||
@@ -119,17 +37,18 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
floatingActionButton: _selectedIndex == 3
|
floatingActionButton: _selectedIndex == 3
|
||||||
? null
|
? null
|
||||||
: FloatingActionButton(
|
: FloatingActionButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => AddScreen(initialIndex: _selectedIndex),
|
builder: (context) =>
|
||||||
|
AddScreen(initialIndex: _selectedIndex),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
tooltip: 'Add',
|
||||||
|
child: const Icon(Icons.add),
|
||||||
),
|
),
|
||||||
);
|
|
||||||
},
|
|
||||||
tooltip: 'Add',
|
|
||||||
child: const Icon(Icons.add),
|
|
||||||
),
|
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
items: const <BottomNavigationBarItem>[
|
items: const <BottomNavigationBarItem>[
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
|
|||||||
Reference in New Issue
Block a user