Professional Documents
Culture Documents
CHENAB CAMPUS
CLASS: BSCS-7
SAP: 70059627
DATE: 21-12-2021
SIGN-UP PAGE
Create_user.dart:
import 'package:firebase_auth/firebase_auth.dart';
class CreateUser {
user(String email, String password) async {
try {
UserCredential userCredential = await FirebaseAuth.instance
.createUserWithEmailAndPassword(email: email, password: password);
return User;
} on FirebaseAuthException catch (e) {
if (e.code == 'weak-password') {
print('The password provided is too weak.');
} else if (e.code == 'email-already-in-use') {
print('The account already exists for that email.');
}
} catch (e) {
print(e);
}
}
}
Sing_up_page.dart
import 'package:flutter/material.dart';
import 'package:mobile_app_dev_proj/create_user.dart';
@override
_LoginPageState createState() => _LoginPageState();
}
return Column(
children: [
//User name Field
TextField(
controller: controllerUserName,
decoration: const InputDecoration(
labelText: 'User Name', prefixIcon: Icon(Icons.text_fields)),
),
//Password Field
TextField(
controller: controllerPassword,
decoration: const InputDecoration(
labelText: 'Password', prefixIcon: Icon(Icons.text_fields)),
),
//Create Account Button
Padding(
padding: const EdgeInsets.all(8.0),
child: GestureDetector(
child: const Text(
"Create Account",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
onTap: () {
CreateUser _user = CreateUser();
_user.user(controllerUserName.text, controllerPassword.text);
},
),
),
],
);
}
}
Main.dart:
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:mobile_app_dev_proj/sing_up_page.dart';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: const Text("home"),
),
body: const LoginPage()),
);
}
}