Using Flutter, I'm trying to verify a user with Firebase, but I'm a bit confused about how to implement the functionality on my registration and login pages. I'll provide the login page, registration page, confirmation email page, and home page below so you can take a look and fix bugs or add features I've missed.
login page
import 'Package:firebase_auth/firebase_auth.dart';
import "package: flutter/material.dart";
Importiere „Paket:thehunt/constants/routes.dart“;
importiere 'Paket: thehunt/views/forgot_password_view.dart';
clase LoginView extiende StatefulWidget {
final VoidCallback showRegisterView;
const LoginView({super.key, benötigt this.showRegisterView});
@Overwrite
Condition
}
Class _LoginViewState extends State
// Text handler
last final TextEditingController _email;
last final TextEditingController _password;
future login() asynchronous {
To try {
espere FirebaseAuth.instance.signInWithEmailAndPassword(
Email: _email.text.trim(),
Password: _password.text.trim(),
);
} in catch FirebaseAuthException(e) {
if (e.code == 'user not found') {
showDialog(
Context: Context,
Constructor: (context) {
volver const AlertDialog(
Content: Text ("User not found"),
);
},
);
} else if (e.code == 'incorrect password') {
showDialog(
Context: Context,
Constructor: (context) {
volver const AlertDialog(
Content: Text('Wrong password'),
);
},
);
} anders {
showDialog(
Context: Context,
Constructor: (context) {
volver const AlertDialog(
Content: Text('Authentication failed'),
);
},
);
}
}
}
@Overwrite
void initState() {
_email = TextEditingController();
_password = TextEditHandler();
super.initState();
}
@Overwrite
override dispose() {
_email.dispose();
_password.dispose();
super.dispose();
}
@Overwrite
Compilation of widgets (BuildContext-Kontext) {
return scaffolding (
backgroundColor: Colores.gris[300],
Body: Safe Area (
Child: Medium (
Tipo: SingleChildScrollView(
child: column (
Principal axis alignment: Principal axis alignment.center,
Kinder: [
constant text (
"Welcome to the Hunt"
style: TextStyle(
fontWeight: FontWeight.negrita,
font size: 30,
),
),
const SizedBox (height: 36),
// email field
Upholstery(
Relleno: const EdgeInsets.symmetric (horizontal: 25.0),
child: container (
Decoration: Box Decoration(
Color: Colors.grey[200],
Grenze: Border.all (Tipo: Colors.white),
radiodelborde: radiodelborde.circular(12),
),
Child: Fill (
Padding: const EdgeInsets.only(left: 20.0),
Child: text field (
Decoration: const DecorationInput(
Borders: InputBorder.none,
hintText: "Enter your email address here",
),
Controller: _email,
enableSuggestions: false,
autocorrect: wrong,
Tastaturtyp: TextInputType.emailAddress,
),
),
),
),
const SizedBox (height: 10),
// Password field
Upholstery(
Relleno: const EdgeInsets.symmetric (horizontal: 25.0),
child: container (
Decoration: Box Decoration(
Color: Colors.grey[200],
Grenze: Border.all (Tipo: Colors.white),
radiodelborde: radiodelborde.circular(12),
),
Child: Fill (
Padding: const EdgeInsets.only(left: 20.0),
Child: text field (
Decoration: const DecorationInput(
Borders: InputBorder.none,
hintText: 'Enter your password',
),
Controller: _password,
dark text: true,
enableSuggestions: false,
autocorrect: wrong,
),
),
),
),
const SizedBox (height: 10),
Upholstery(
Relleno: const EdgeInsets.symmetric (horizontal: 25.0),
child: line(
main axis align: main axis align.end,
Kinder: [
gesture detector (
on tap: () {
Browser.push(
Context,
MaterialPageRoute(
Constructor: (context) {
Anterior ForgotPasswordView();
},
),
);
},
Type: Text(
'Have you forgotten your password?',
style: TextStyle(
Color: colors.blue,
fontWeight: FontWeight.negrita,
),
),
),
],
),
),
//Login button
const SizedBox (height: 10),
Upholstery(
Relleno: const EdgeInsets.symmetric(
horizontal: 25.0,
),
Tipo: GestureDetector(
onTap: login,
child: container (
Relleno: EdgeInsets.all(20),
Decoration: Box Decoration(
Color: Colors.deepPurple,
radiodelborde: radiodelborde.circular(12),
),
Type: const Center (
Type: Text(
'Registry',
style: TextStyle(
Color: colors.white,
fontWeight: FontWeight.negrita,
font size: 18,
),
)),
),
),
),
const SizedBox (height: 36),
// Join now
Line(
Principal axis alignment: Principal axis alignment.center,
Kinder: [
gesture detector (
//onTap: widget.showRegisterPage,
Type: Text(
'Aren't you registered yet?',
style: TextStyle(
fontWeight: FontWeight.negrita,
),
),
),
gesture detector (
al pulsar: widget.showRegisterView,
Type: Text(
' Join now',
style: TextStyle(
Color: colors.blue,
fontWeight: FontWeight.negrita,
),
),
),
],
)
// Text button (
// on Press: () {
// Navigator.of(context).pushNamedAndRemoveUntil(
// register route,
// (path) => false,
//);
// },
// child: const Text('Not registered yet? Register here'),
// )
],
),
),
),
),
);
}
}
registration site
Import "Packet: cloud_firestore/cloud_firestore.dart";
import "package: flutter/material.dart";
Importiere „Paket:thehunt/constants/routes.dart“;
import 'Package:firebase_auth/firebase_auth.dart';
The RegisterView class extends StatefulWidget {
final VoidCallback showLoginView;
const RegistrarVista({
super clave,
requerido this.showLoginView,
});
@Overwrite
Condition
}
Class _RegisterViewState extends State
last final TextEditingController _email;
last final TextEditingController _password;
TextEditingController final tardĂo _confirmpassword;
last final TextEditingController _username;
@Overwrite
void initState() {
_email = TextEditingController();
_password = TextEditHandler();
_confirmpassword = TextEditingController();
_username = TextEditingController();
super.initState();
}
@Overwrite
override dispose() {
_email.dispose();
_password.dispose();
_confirmpassword.dispose();
_username.dispose();
super.dispose();
}
future register() async {
To try {
if (passwordConfirmed()) {
//Create user
espere FirebaseAuth.instance.createUserWithEmailAndPassword(
Email: _email.text.trim(),
Password: _password.text.trim(),
);
}
//Add user details
Add user details (
_username.text.trim(),
_email.text.trim(),
);
} in catch FirebaseAuthException(e) {
if (e.code == 'weak password') {
showDialog(
Context: Context,
Constructor: (context) {
volver const AlertDialog(
Content: Text('Weak Password'),
);
},
);
} else if (e.code == 'email-bereits-in-use') {
showDialog(
Context: Context,
Constructor: (context) {
volver const AlertDialog(
Content: Text('Email is already in use'),
);
},
);
} else if (e.code == 'invalid email') {
showDialog(
Context: Context,
Constructor: (context) {
volver const AlertDialog(
Content: text ("invalid email address entered"),
);
},
);
}
}
}
Future addUserDetails(String username, String email) asynchronous {
espere FirebaseFirestore.instance.collection('usuarios').add({
'username': username,
'Email Email,
});
}
bool confirmedPassword() {
if (_password.text.trim() == _confirmpassword.text.trim()) {
return true;
} anders {
false return;
}
}
@Overwrite
Compilation of widgets (BuildContext-Kontext) {
return scaffolding (
backgroundColor: Colores.gris[300],
Body: Safe Area (
Child: Medium (
Tipo: SingleChildScrollView(
child: column (
Principal axis alignment: Principal axis alignment.center,
Kinder: [
Text(
'Sign up below!',
style: TextStyle(
fontWeight: FontWeight.negrita,
font size: 30,
),
),
SizedBox (height: 36),
//Username text field
Upholstery(
Relleno: const EdgeInsets.symmetric (horizontal: 25.0),
child: container (
Decoration: Box Decoration(
Color: Colors.grey[200],
Grenze: Border.all (Tipo: Colors.white),
radiodelborde: radiodelborde.circular(12),
),
Child: Fill (
Padding: const EdgeInsets.only(left: 20.0),
Child: text field (
Decoration: const DecorationInput(
Borders: InputBorder.none,
hintText: "Enter your username here",
),
Controller: _username,
enableSuggestions: false,
autocorrect: wrong,
Tastaturtyp: TextInputType.emailAddress,
),
),
),
),
const SizedBox (height: 10),
// email field
Upholstery(
Relleno: const EdgeInsets.symmetric (horizontal: 25.0),
child: container (
Decoration: Box Decoration(
Color: Colors.grey[200],
Grenze: Border.all (Tipo: Colors.white),
radiodelborde: radiodelborde.circular(12),
),
Child: Fill (
Padding: const EdgeInsets.only(left: 20.0),
Child: text field (
Decoration: const DecorationInput(
Borders: InputBorder.none,
hintText: "Enter your email address here",
),
Controller: _email,
enableSuggestions: false,
autocorrect: wrong,
Tastaturtyp: TextInputType.emailAddress,
),
),
),
),
const SizedBox (height: 10),
// Password field
Upholstery(
Relleno: const EdgeInsets.symmetric (horizontal: 25.0),
child: container (
Decoration: Box Decoration(
Color: Colors.grey[200],
Grenze: Border.all (Tipo: Colors.white),
radiodelborde: radiodelborde.circular(12),
),
Child: Fill (
Padding: const EdgeInsets.only(left: 20.0),
Child: text field (
Decoration: const DecorationInput(
Borders: InputBorder.none,
hintText: 'Enter your password',
),
Controller: _password,
dark text: true,
enableSuggestions: false,
autocorrect: wrong,
Tastaturtyp: TextInputType.emailAddress,
),
),
),
),
const SizedBox (height: 10),
//Confirm password field
Upholstery(
Relleno: const EdgeInsets.symmetric (horizontal: 25.0),
child: container (
Decoration: Box Decoration(
Color: Colors.grey[200],
Grenze: Border.all (Tipo: Colors.white),
radiodelborde: radiodelborde.circular(12),
),
Child: Fill (
Padding: const EdgeInsets.only(left: 20.0),
Child: text field (
Decoration: const DecorationInput(
Borders: InputBorder.none,
hintText: "Confirm password",
),
Controller: _confirmpassword,
dark text: true,
enableSuggestions: false,
autocorrect: wrong,
Tastaturtyp: TextInputType.emailAddress,
),
),
),
),
// register button
const SizedBox (height: 10),
Upholstery(
Relleno: const EdgeInsets.symmetric(
horizontal: 25.0,
),
Tipo: GestureDetector(
onTap: record,
child: container (
Relleno: EdgeInsets.all(20),
Decoration: Box Decoration(
Color: Colors.deepPurple,
radiodelborde: radiodelborde.circular(12),
),
Type: const Center (
Type: Text(
'Check in',
style: TextStyle(
Color: colors.white,
fontWeight: FontWeight.negrita,
font size: 18,
),
)),
),
),
),
const SizedBox (height: 36),
// Join now
Line(
Principal axis alignment: Principal axis alignment.center,
Kinder: [
Text(
'Already registered?',
style: TextStyle(
fontWeight: FontWeight.negrita,
),
),
gesture detector (
al pulsar: widget.showLoginView,
Type: Text(
'Login now',
style: TextStyle(
Color: colors.blue,
fontWeight: FontWeight.negrita,
),
),
),
],
)
// Text button (
// on Press: () {
// Navigator.of(context).pushNamedAndRemoveUntil(
// register route,
// (path) => false,
//);
// },
// child: const Text('Not registered yet? Register here'),
// )
],
),
),
),
),
);
}
}
home page
import 'Package:firebase_auth/firebase_auth.dart';
import "package: flutter/material.dart";
Importar "paquete: thehunt/views/hunt/current_location_view.dart";
HomeView class extends StatefulWidget {
const HomeView({super.clave});
@Overwrite
Condition
}
Class _HomeViewState extends State
last user = FirebaseAuth.instance.currentUser!;
@Overwrite
Compilation of widgets (BuildContext-Kontext) {
return scaffolding (
Body: Medium (
child: column (
Principal axis alignment: Principal axis alignment.center,
Kinder: [
Text('Logged in as: ' + user.email!),
ButtonMaterial(
onPressed: () {
FirebaseAuth.instancia.signOut();
},
Color: Colors.deepPurple[200],
Child: Text('unsubscribe'),
),
ButtonMaterial(
onPressed: () {
Navigator.of (context)
.push(MaterialPageRoute(Constructor: (BuildContext-Kontext) {
return const CurrentLocationScreen();
}));
},
Color: Colors.deepPurple[200],
Tipo: const Text('UserLocation')),
],
),
),
);
}
}
confirm email page
import "package: flutter/material.dart";
Importiere „Paket:mynotes/constants/routes.dart“;
importiere „Paket:mynotes/services/auth/auth_service.dart“;
class VerifyEmailView extends StatefulWidget {
const VerifyEmailView({super.clave});
@Overwrite
Condition
}
The _VerifyEmailViewState class extends the state
@Overwrite
Compilation of widgets (BuildContext-Kontext) {
return scaffolding (
Application Bar: Application Bar(
Title: const Text('Confirm Email'),
),
Body: Column (
Kinder: [
constant text (
"We've sent you a confirmation email. Please open it to verify your account."
),
Text(
"If you haven't received a confirmation email yet, please click the button below",
),
Text button (
onPressed: () async {
espere AuthService.firebase().sendEmailVerification();
},
child: const Text('Send confirmation email'),
),
Text button (
onPressed: () async {
espere AuthService.firebase().logOut();
Navigator.of(contexto).pushNamedAndRemoveUntil(
log Path,
(path) => false,
);
},
child: const Text('restart'),
)
],
),
);
}
}
about us
We are a professional custom writing website. If you've been searching for a question and stumbled across our site, know that you've come to the right place for help with your coursework.
Do you do any kind of course?
Yes. We have reported our previous orders to represent our experience. Since we've asked this question before, we can do it for you as well. To make sure we make it perfect, please fill out our order form. Completing the order form correctly will help our team with references, specifications and future communications.
Is it difficult to order?
1. Click "place an orderTab in the top menu or "order now” below and a new page will appear with an order form to fill out.
2. Enter your paper requirements in the "PAPER INFORMATION"Section and Click"PRICE CALCULATION” at the bottom to calculate the price of your order.
3. Enter the academic level of your paper, the due date, and the required number of pages from the dropdown menus.
4. Click "LAST STEP' to enter your registration details and create an account with us for record keeping, then click 'TO CHECK"at the end of the page.
5. From there the payment sections will appear, follow the guided payment process and your order will be available for our writing team to process.
Do you need this homework or another paper?
Click here and get a 25% discount
discount codeSPAREN25